Skip to content

Commit 27852bc

Browse files
authored
Update test_pivot.py
BUG: Incorrect values shown by pivot_table() pandas-dev#21378
1 parent 8d5032a commit 27852bc

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pandas/tests/reshape/test_pivot.py

+19
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,25 @@ def test_pivot_table_dropna_categoricals(self, dropna):
142142

143143
tm.assert_frame_equal(result, expected)
144144

145+
def test_pivot_with_new_patch(self, dropna):
146+
# gh-21133
147+
df = pd.DataFrame(
148+
{'A': pd.Categorical(['left', 'low', 'high', 'low', 'high'],
149+
categories=['low', 'high', 'left'],
150+
ordered=True),
151+
'B': range(5)})
152+
153+
result = df.pivot_table(index='A', values='B', dropna=dropna)
154+
expected = pd.DataFrame(
155+
{'B': [2, 3, 0]},
156+
index=pd.Index(
157+
pd.Categorical.from_codes([0, 1, 2],
158+
categories=['low', 'high', 'left'],
159+
ordered=True),
160+
name='A'))
161+
162+
tm.assert_frame_equal(result, expected)
163+
145164
def test_pivot_with_non_observable_dropna(self, dropna):
146165
# gh-21133
147166
df = pd.DataFrame(

0 commit comments

Comments
 (0)