Skip to content

Commit ded4775

Browse files
authored
Update test_pivot.py
TST: add additional test cases for pivot_table with categorical data pandas-dev#21370
1 parent abfac97 commit ded4775

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pandas/tests/reshape/test_pivot.py

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

143143
tm.assert_frame_equal(result, expected)
144144

145+
def test_pivot_with_non_observable_dropna_civ(self, dropna):
146+
# gh-21370
147+
df=pd.DataFrame(
148+
{"In":pd.Categorical([np.nan,'low','high','low','high','high',np.nan],
149+
categories=['low','high'],ordered=True),
150+
"Col":["A","B","C","C","C","A","B"],
151+
"Val":range(7)})
152+
result=df.pivot_table(index="In",columns="Col",values="Val",dropna=dropna)
153+
expected=pd.DataFrame(
154+
{'A':[np.nan,5],'B':[1,np.nan],'C':[3.0,3.0]},
155+
index=pd.Index(
156+
pd.Categorical.from_codes([0,1],
157+
categories=['low','high'],
158+
ordered=True),
159+
name='In'))
160+
tm.assert_frame_equal(result,expected)
161+
145162
def test_pivot_with_non_observable_dropna(self, dropna):
146163
# gh-21133
147164
df = pd.DataFrame(

0 commit comments

Comments
 (0)