Skip to content

Commit b14dda9

Browse files
authored
DataFrame pivot_table nunique aggfunc test GH#29080 (#52082)
Signed-off-by: Liang Yan <[email protected]>
1 parent 805d765 commit b14dda9

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

pandas/tests/reshape/test_pivot.py

+37
Original file line numberDiff line numberDiff line change
@@ -2378,6 +2378,43 @@ def test_pivot_table_with_mixed_nested_tuples(self, using_array_manager):
23782378
expected["small"] = expected["small"].astype("int64")
23792379
tm.assert_frame_equal(result, expected)
23802380

2381+
def test_pivot_table_aggfunc_nunique_with_different_values(self):
2382+
test = DataFrame(
2383+
{
2384+
"a": range(10),
2385+
"b": range(10),
2386+
"c": range(10),
2387+
"d": range(10),
2388+
}
2389+
)
2390+
2391+
columnval = MultiIndex.from_arrays(
2392+
[
2393+
["nunique" for i in range(10)],
2394+
["c" for i in range(10)],
2395+
range(10),
2396+
],
2397+
names=(None, None, "b"),
2398+
)
2399+
nparr = np.full((10, 10), np.NaN)
2400+
np.fill_diagonal(nparr, 1.0)
2401+
2402+
expected = DataFrame(nparr, index=Index(range(10), name="a"), columns=columnval)
2403+
result = test.pivot_table(
2404+
index=[
2405+
"a",
2406+
],
2407+
columns=[
2408+
"b",
2409+
],
2410+
values=[
2411+
"c",
2412+
],
2413+
aggfunc=["nunique"],
2414+
)
2415+
2416+
tm.assert_frame_equal(result, expected)
2417+
23812418

23822419
class TestPivot:
23832420
def test_pivot(self):

0 commit comments

Comments
 (0)