Skip to content

Commit f5f62c0

Browse files
committed
fix: address review feedback
1 parent 7708b14 commit f5f62c0

File tree

2 files changed

+4
-23
lines changed

2 files changed

+4
-23
lines changed

pandas/core/frame.py

+2
Original file line numberDiff line numberDiff line change
@@ -9295,6 +9295,8 @@ def pivot(
92959295
**kwargs : dict
92969296
Optional keyword arguments to pass to ``aggfunc``.
92979297
9298+
.. versionadded:: 3.0.0
9299+
92989300
Returns
92999301
-------
93009302
DataFrame

pandas/tests/reshape/test_pivot.py

+2-23
Original file line numberDiff line numberDiff line change
@@ -2060,6 +2060,7 @@ def test_pivot_string_as_func(self):
20602060

20612061
@pytest.mark.parametrize("kwargs", [{"a": 2}, {"a": 2, "b": 3}, {"b": 3, "a": 2}])
20622062
def test_pivot_table_kwargs(self, kwargs):
2063+
# GH#57884
20632064
def f(x, a, b=3):
20642065
return x.sum() * a + b
20652066

@@ -2079,17 +2080,11 @@ def g(x):
20792080
expected = pivot_table(df, index="A", columns="B", values="X", aggfunc=g)
20802081
tm.assert_frame_equal(result, expected)
20812082

2082-
expected = DataFrame(
2083-
[[np.nan, 43.0, 13.0], [15.0, np.nan, 23.0]],
2084-
columns=Index(["one", "three", "two"], name="B"),
2085-
index=Index(["bad", "good"], name="A"),
2086-
)
2087-
tm.assert_frame_equal(result, expected)
2088-
20892083
@pytest.mark.parametrize(
20902084
"kwargs", [{}, {"b": 10}, {"a": 3}, {"a": 3, "b": 10}, {"b": 10, "a": 3}]
20912085
)
20922086
def test_pivot_table_kwargs_margin(self, data, kwargs):
2087+
# GH#57884
20932088
def f(x, a=5, b=7):
20942089
return (x.sum() + b) * a
20952090

@@ -2117,22 +2112,6 @@ def g(x):
21172112

21182113
tm.assert_frame_equal(result, expected)
21192114

2120-
grand_margin = g(data["D"])
2121-
2122-
margin_col = pivot_table(
2123-
data, values="D", index=["A", "B"], aggfunc=g, fill_value=0
2124-
)
2125-
margin_col.loc[("All", ""), "D"] = grand_margin
2126-
margin_col = margin_col["D"]
2127-
margin_col.name = "All"
2128-
tm.assert_series_equal(result["All"], margin_col)
2129-
2130-
margin_row = pivot_table(data, values="D", columns="C", aggfunc=g, fill_value=0)
2131-
margin_row["All"] = grand_margin
2132-
margin_row.index = [""]
2133-
margin_row.index.name = "B"
2134-
tm.assert_frame_equal(result.loc["All"], margin_row)
2135-
21362115
@pytest.mark.parametrize(
21372116
"f, f_numpy",
21382117
[

0 commit comments

Comments
 (0)