Skip to content

Commit 3e7dc06

Browse files
ganevgvMateusz Górski
authored and
Mateusz Górski
committed
TST: add test for empty frame groupby dtypes consistency (pandas-dev#29455)
Closes pandas-dev#20888
1 parent 3e126fc commit 3e7dc06

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pandas/tests/test_multilevel.py

+14
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,20 @@ def test_frame_dict_constructor_empty_series(self):
15331533
DataFrame({"foo": s1, "bar": s2, "baz": s3})
15341534
DataFrame.from_dict({"foo": s1, "baz": s3, "bar": s2})
15351535

1536+
@pytest.mark.parametrize("d", [4, "d"])
1537+
def test_empty_frame_groupby_dtypes_consistency(self, d):
1538+
# GH 20888
1539+
group_keys = ["a", "b", "c"]
1540+
df = DataFrame({"a": [1], "b": [2], "c": [3], "d": [d]})
1541+
1542+
g = df[df.a == 2].groupby(group_keys)
1543+
result = g.first().index
1544+
expected = MultiIndex(
1545+
levels=[[1], [2], [3]], codes=[[], [], []], names=["a", "b", "c"]
1546+
)
1547+
1548+
tm.assert_index_equal(result, expected)
1549+
15361550
def test_multiindex_na_repr(self):
15371551
# only an issue with long columns
15381552
df3 = DataFrame(

0 commit comments

Comments
 (0)