Skip to content

Commit 3396aa7

Browse files
louisjbrockmendel
louis
authored andcommitted
TST: Refactor test for empty groupby with categorical data.
1 parent 4fec5df commit 3396aa7

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

pandas/tests/groupby/test_categorical.py

+12
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,18 @@ 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+
df = pd.DataFrame({"A": [None] * 3, "B": pd.Categorical(["train", "train", "test"])})
787+
result = df.groupby("A").first()["B"]
788+
expected = pd.Series(
789+
pd.Categorical([], categories=["test", "train"]),
790+
index=pd.Series([], dtype="object", name="A"),
791+
name="B",
792+
)
793+
tm.assert_series_equal(result, expected)
794+
795+
784796
def test_sort():
785797

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

pandas/tests/groupby/test_groupby.py

-12
Original file line numberDiff line numberDiff line change
@@ -1825,18 +1825,6 @@ def test_groupby_empty_list_raises():
18251825
df.groupby([[]])
18261826

18271827

1828-
def test_groupby_with_empty_category():
1829-
# GH-9614
1830-
df = pd.DataFrame({"id": [None] * 3, "spam": [None] * 3})
1831-
df["spam"] = df["spam"].astype("category")
1832-
df["spam"] == "spam" # works as expected
1833-
result = df.groupby("id").first()["spam"] == "spam"
1834-
expected = Series(
1835-
[], name="spam", dtype=bool, index=pd.Series([], dtype="object", name="id")
1836-
)
1837-
tm.assert_series_equal(result, expected)
1838-
1839-
18401828
def test_groupby_multiindex_series_keys_len_equal_group_axis():
18411829
# GH 25704
18421830
index_array = [["x", "x"], ["a", "b"], ["k", "k"]]

0 commit comments

Comments
 (0)