Skip to content

Commit 3f0eb24

Browse files
author
Sumanau Sareen
committed
Added test for ensuring empty df has an empty index.
1 parent f6efb8d commit 3f0eb24

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3392,7 +3392,7 @@ def _ensure_valid_index(self, value):
33923392
passed value.
33933393
"""
33943394
# GH5632, make sure that we are a Series convertible
3395-
if not len(self.index) and len(value) and is_list_like(value):
3395+
if not len(self.index) and is_list_like(value) and len(value):
33963396
try:
33973397
value = Series(value)
33983398
except (ValueError, NotImplementedError, TypeError):

pandas/tests/indexing/test_indexing.py

+5
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,11 @@ def test_index_type_coercion(self):
627627
idxr(s2)['0'] = 0
628628
assert s2.index.is_object()
629629

630+
def test_empty_index_for_empty_dataframe(self):
631+
empty_df = pd.DataFrame(columns=['A'])
632+
df_with_empty_value = pd.DataFrame(columns=['A'], data=[])
633+
assert df_with_empty_value.index.dtype == empty_df.index.dtype
634+
630635

631636
class TestMisc(Base):
632637

0 commit comments

Comments
 (0)