Skip to content

Commit 47fb344

Browse files
author
Sumanau Sareen
committed
Added test for ensuring empty df has an empty index.
1 parent 1a1baa2 commit 47fb344

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
@@ -3402,7 +3402,7 @@ def _ensure_valid_index(self, value):
34023402
passed value.
34033403
"""
34043404
# GH5632, make sure that we are a Series convertible
3405-
if not len(self.index) and len(value) and is_list_like(value):
3405+
if not len(self.index) and is_list_like(value) and len(value):
34063406
try:
34073407
value = Series(value)
34083408
except (ValueError, NotImplementedError, TypeError):

pandas/tests/indexing/test_indexing.py

+5
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,11 @@ def test_index_type_coercion(self):
717717
idxr(s2)['0'] = 0
718718
assert s2.index.is_object()
719719

720+
def test_empty_index_for_empty_dataframe(self):
721+
empty_df = pd.DataFrame(columns=['A'])
722+
df_with_empty_value = pd.DataFrame(columns=['A'], data=[])
723+
assert df_with_empty_value.index.dtype == empty_df.index.dtype
724+
720725

721726
class TestMisc(Base):
722727

0 commit comments

Comments
 (0)