Skip to content
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

TST: Added test for pivot_table with int64 dtype and dropna parameter #60374

Merged
merged 3 commits into from
Nov 21, 2024
Merged
Changes from 2 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
9 changes: 6 additions & 3 deletions pandas/tests/reshape/test_pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2376,17 +2376,20 @@ def test_pivot_table_with_margins_and_numeric_columns(self):

tm.assert_frame_equal(result, expected)

def test_pivot_ea_dtype_dropna(self, dropna):
@pytest.mark.parametrize("dtype", ["Int64", "int64"])
def test_pivot_ea_dtype_dropna(self, dropna, dtype):
# GH#47477
df = DataFrame({"x": "a", "y": "b", "age": Series([20, 40], dtype="Int64")})
# GH#47971
df = DataFrame({"x": "a", "y": "b", "age": Series([20, 40], dtype=dtype)})
result = df.pivot_table(
index="x", columns="y", values="age", aggfunc="mean", dropna=dropna
)
expected_dtype = "float64" if dtype == "int64" else "Float64"
Copy link
Member

Choose a reason for hiding this comment

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

Could you put this in the parametrize instead?

expected = DataFrame(
[[30]],
index=Index(["a"], name="x"),
columns=Index(["b"], name="y"),
dtype="Float64",
dtype=expected_dtype,
)
tm.assert_frame_equal(result, expected)

Expand Down
Loading