Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions pandas/tests/reshape/test_pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,30 @@ def test_pivot_table_dropna_categoricals(self, dropna):

tm.assert_frame_equal(result, expected)

def test_pivot_with_non_observable_dropna_civ(self, dropna):
# gh-21370
arr = [np.nan, 'low', 'high', 'low', np.nan]
df = pd.DataFrame({
"In": pd.Categorical(arr,
categories=['low', 'high'],
ordered=True),
"Col": ["A", "B", "C", "A", "B"],
Copy link
Member

@jschendel jschendel Jun 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also be a Categorical with NaN values present in order to recreate the issue.

"Val": range(1, 6)
})
result = df.pivot_table(index="In", columns="Col", values="Val",
dropna=dropna)
expected = pd.DataFrame({
'A': [4.0, np.nan],
'B': [2.0, np.nan],
'C': [np.nan, 3.0]},
index=pd.Index(
pd.Categorical.from_codes(
[0, 1],
categories=['low', 'high'],
ordered=True),
name='In'))
tm.assert_frame_equal(result, expected)

def test_pivot_with_non_observable_dropna(self, dropna):
# gh-21133
df = pd.DataFrame(
Expand Down