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 5 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
19 changes: 19 additions & 0 deletions pandas/tests/reshape/test_pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,25 @@ 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', 'high', 'high', 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.

Even if this technically passes LINTing I find the indentation very difficult to read. Can you try putting each key of the dict at the start of the line to see if that improves readability?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

alright, I will look into it

categories=['low', 'high'],
ordered=True), "Col": ["A",
"B", "C", "C", "C", "A", "B"],
"Val": range(7)})
result = df.pivot_table(index="In", columns="Col", values="Val",
dropna=dropna)
expected = pd.DataFrame(
{'A': [np.nan, 5], 'B': [1, np.nan], 'C': [3.0, 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