Skip to content

Commit b8b2011

Browse files
author
kpflugshaupt
committed
Extend unit test with code sample from pandas-dev#25167
1 parent 2abf281 commit b8b2011

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pandas/tests/groupby/test_categorical.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,16 @@ def test_dataframe_categorical_ordered_observed_sort(ordered, observed, sort):
476476
aggr = pd.Series(result.array)
477477
if not observed:
478478
aggr[aggr.isna()] = 'AWOL'
479-
tm.assert_equal(label, aggr)
479+
tm.assert_series_equal(label, aggr)
480+
481+
# GH 25167: Groupby with observed=True doesn't sort
482+
df = pd.DataFrame({'A': pd.Categorical(['b', 'a']), 'B': [1, 2]})
483+
result = df.groupby('A', observed=True).sum()
484+
expected = pd.DataFrame({'B': [2, 1]},
485+
index=pd.CategoricalIndex(['b', 'a'], categories=['a', 'b'],
486+
ordered=False, name='A', dtype='category'),
487+
dtype='int')
488+
tm.assert_frame_equal(result, expected)
480489

481490

482491
def test_datetime():

0 commit comments

Comments
 (0)