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 6 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
23 changes: 23 additions & 0 deletions pandas/tests/reshape/test_pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,29 @@ 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,
Copy link
Member

Choose a reason for hiding this comment

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

Move the angled bracket to the line above. Move the word arr to the next line and move the subsequent kwargs up to that line accordingly (so long as they fit)

categories=['low', 'high'],
ordered=True),
"Col": ["A", "B", "C", "A", "B"],
"Val": range(1, 6)})
result = df.pivot_table(index="In", columns="Col", values="Val",
dropna=dropna)
expected = pd.DataFrame(
{
Copy link
Member

Choose a reason for hiding this comment

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

Move this up a line

'A': [4.0, np.nan],
'B': [2.0, np.nan],
'C': [np.nan, 3.0]},
index=pd.Index(
pd.Categorical.from_codes([0, 1],
Copy link
Member

Choose a reason for hiding this comment

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

Try moving [0, 1] to the next line and moving the subsequent kwargs up

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