Skip to content

Commit 9ac5373

Browse files
committed
moar tests
1 parent 436ada9 commit 9ac5373

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pandas/tests/groupby/test_categorical.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,27 @@ def test_preserve_categorical_dtype():
697697
tm.assert_frame_equal(result2, expected)
698698

699699

700+
@pytest.mark.parametrize(
701+
'func, values',
702+
[('first', ['second', 'first']),
703+
('last', ['fourth', 'third']),
704+
('min', ['fourth', 'first']),
705+
('max', ['second', 'third'])])
706+
def test_preserve_on_ordered_ops(func, values):
707+
# gh-18502
708+
# preserve the categoricals on ops
709+
c = pd.Categorical(['first', 'second', 'third', 'fourth'], ordered=True)
710+
df = pd.DataFrame(
711+
{'payload': [-1, -2, -1, -2],
712+
'col': c})
713+
g = df.groupby('payload')
714+
result = getattr(g, func)()
715+
expected = pd.DataFrame(
716+
{'payload': [-2, -1],
717+
'col': pd.Series(values, dtype=c.dtype)}).set_index('payload')
718+
tm.assert_frame_equal(result, expected)
719+
720+
700721
def test_categorical_no_compress():
701722
data = Series(np.random.randn(9))
702723

0 commit comments

Comments
 (0)