diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index 3ec60d50f2792..ca95dde1a20c9 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -161,6 +161,24 @@ def test_pivot_with_non_observable_dropna(self, dropna): tm.assert_frame_equal(result, expected) + # gh-21378 + df = pd.DataFrame( + {'A': pd.Categorical(['left', 'low', 'high', 'low', 'high'], + categories=['low', 'high', 'left'], + ordered=True), + 'B': range(5)}) + + result = df.pivot_table(index='A', values='B', dropna=dropna) + expected = pd.DataFrame( + {'B': [2, 3, 0]}, + index=pd.Index( + pd.Categorical.from_codes([0, 1, 2], + categories=['low', 'high', 'left'], + ordered=True), + name='A')) + + tm.assert_frame_equal(result, expected) + def test_pass_array(self): result = self.data.pivot_table( 'D', index=self.data.A, columns=self.data.C)