Skip to content

Commit 719ab02

Browse files
louishuynhjreback
authored andcommitted
TST: Test type issue fix in empty groupby from DataFrame with categorical (#29355)
1 parent e5c3907 commit 719ab02

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pandas/tests/groupby/test_categorical.py

+16
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,22 @@ def test_categorical_no_compress():
781781
tm.assert_numpy_array_equal(result, exp)
782782

783783

784+
def test_groupby_empty_with_category():
785+
# GH-9614
786+
# test fix for when group by on None resulted in
787+
# coercion of dtype categorical -> float
788+
df = pd.DataFrame(
789+
{"A": [None] * 3, "B": pd.Categorical(["train", "train", "test"])}
790+
)
791+
result = df.groupby("A").first()["B"]
792+
expected = pd.Series(
793+
pd.Categorical([], categories=["test", "train"]),
794+
index=pd.Series([], dtype="object", name="A"),
795+
name="B",
796+
)
797+
tm.assert_series_equal(result, expected)
798+
799+
784800
def test_sort():
785801

786802
# http://stackoverflow.com/questions/23814368/sorting-pandas-

0 commit comments

Comments
 (0)