Skip to content

TST : Adding new test case for pivot_table() with Categorical data #21381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
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