Skip to content

Commit

Permalink
BUG: Add test for pandas-dev#28641 to ensure that error does not occu…
Browse files Browse the repository at this point in the history
…r again
  • Loading branch information
phofl authored and patrick committed Mar 28, 2020
1 parent e88c392 commit 35a4dd6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pandas/tests/groupby/aggregate/test_aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,13 @@ def test_aggregate_mixed_types():
tm.assert_frame_equal(result, expected)


def test_aggregate_categorical_lost_index():
# GH: 28641
result = pd.DataFrame({"A": [1997], "B": pd.Series(["b"], dtype="category").cat.as_ordered()}).groupby("A").agg({"B": "min"})
expected = pd.DataFrame({"B": ["b"]}, index=pd.Index([1997], name="A"))
tm.assert_frame_equal(result, expected)


@pytest.mark.xfail(reason="Not implemented.")
def test_aggregate_udf_na_extension_type():
# https://github.com/pandas-dev/pandas/pull/31359
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/groupby/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1380,3 +1380,11 @@ def test_groupby_agg_non_numeric():

result = df.groupby([1, 2, 1]).nunique()
tm.assert_frame_equal(result, expected)


def test_groupy_first_returns_categorical():
# GH 28641: Issue mentioned in first comment.
df = pd.DataFrame({"A": [1997], "B": pd.Series(["b"], dtype="category").cat.as_ordered()})
result = df.groupby("A")["B"].first()
expected = pd.Series(["b"], index=pd.Index([1997], name="A"), name="B")
tm.assert_series_equal(result, expected)

0 comments on commit 35a4dd6

Please sign in to comment.