Skip to content

DataFrame pivot_table nunique aggfunc test GH#29080 #52082

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

Merged
merged 1 commit into from
Mar 24, 2023
Merged
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
37 changes: 37 additions & 0 deletions pandas/tests/reshape/test_pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2378,6 +2378,43 @@ def test_pivot_table_with_mixed_nested_tuples(self, using_array_manager):
expected["small"] = expected["small"].astype("int64")
tm.assert_frame_equal(result, expected)

def test_pivot_table_aggfunc_nunique_with_different_values(self):
test = DataFrame(
{
"a": range(10),
"b": range(10),
"c": range(10),
"d": range(10),
}
)

columnval = MultiIndex.from_arrays(
[
["nunique" for i in range(10)],
["c" for i in range(10)],
range(10),
],
names=(None, None, "b"),
)
nparr = np.full((10, 10), np.NaN)
np.fill_diagonal(nparr, 1.0)

expected = DataFrame(nparr, index=Index(range(10), name="a"), columns=columnval)
result = test.pivot_table(
index=[
"a",
],
columns=[
"b",
],
values=[
"c",
],
aggfunc=["nunique"],
)

tm.assert_frame_equal(result, expected)


class TestPivot:
def test_pivot(self):
Expand Down