From eeab4488f67ffc41e4f0e76f201180c02d8a4d76 Mon Sep 17 00:00:00 2001 From: Liang Yan Date: Mon, 20 Mar 2023 09:55:37 +0800 Subject: [PATCH] DataFrame pivot_table nunique aggfunc test GH#29080 Signed-off-by: Liang Yan --- pandas/tests/reshape/test_pivot.py | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index 93217fc4ce3b0..3df16d876638a 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -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):