Skip to content

Commit 0912f05

Browse files
committed
Fixed pandas-dev#38419 - BUG: set_index screws up the dtypes on empty DataFrames
1 parent 40793c1 commit 0912f05

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

pandas/tests/frame/methods/test_set_index.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,10 @@ def test_set_index_empty_dataframe(self):
5353
{"a": Series(dtype="datetime64[ns]"), "b": Series(dtype="int64"), "c": []}
5454
)
5555

56-
if df.empty:
57-
df = DataFrame(columns=list(df.columns.values))
58-
59-
expected = df.set_index(["a", "b"])
60-
assert (df.loc[:, ["a", "b"]].dtypes == expected.index.to_frame().dtypes).all()
61-
56+
expected = df.set_index(["a", "b"]).reset_index()
57+
tm.assert_frame_equal(df.reset_index(drop = True),expected)
58+
assert df.empty is True
59+
6260
def test_set_index_multiindexcolumns(self):
6361
columns = MultiIndex.from_tuples([("foo", 1), ("foo", 2), ("bar", 1)])
6462
df = DataFrame(np.random.randn(3, 3), columns=columns)

0 commit comments

Comments
 (0)