Skip to content

Commit 4d53479

Browse files
committed
DataFrame pivot_table nunique aggfunc test GH#29080
Signed-off-by: Liang Yan <[email protected]>
1 parent d22d1f2 commit 4d53479

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

pandas/tests/reshape/test_pivot.py

+38
Original file line numberDiff line numberDiff line change
@@ -2378,6 +2378,44 @@ 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+
2400+
nparr = np.full((10, 10), np.NaN)
2401+
np.fill_diagonal(nparr, 1.0)
2402+
2403+
expected = DataFrame(nparr, index=Index(range(10), name="a"), columns=columnval)
2404+
result = test.pivot_table(
2405+
index=[
2406+
"a",
2407+
],
2408+
columns=[
2409+
"b",
2410+
],
2411+
values=[
2412+
"c",
2413+
],
2414+
aggfunc=["nunique"],
2415+
)
2416+
2417+
tm.assert_frame_equal(result, expected)
2418+
23812419

23822420
class TestPivot:
23832421
def test_pivot(self):

0 commit comments

Comments
 (0)