Skip to content

Commit 1fd7605

Browse files
committed
Add test for DataFrame.agg with *args, **kwargs
1 parent 18c24e2 commit 1fd7605

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

pandas/tests/frame/apply/test_frame_apply.py

+28
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,34 @@ def test_agg_cython_table_raises(self, df, func, expected, axis):
14631463
with pytest.raises(expected, match=msg):
14641464
df.agg(func, axis=axis)
14651465

1466+
@pytest.mark.parametrize("axis", [0, 1])
1467+
@pytest.mark.parametrize(
1468+
"args, kwargs",
1469+
[
1470+
((1, 2, 3), {}),
1471+
((8, 7, 15), {}),
1472+
((1, 2), {}),
1473+
((1,), {"b": 2}),
1474+
((), {"a": 1, "b": 2}),
1475+
((), {"a": 2, "b": 1}),
1476+
((), {"a": 1, "b": 2, "c": 3}),
1477+
],
1478+
)
1479+
def test_agg_args_kwargs(self, axis, args, kwargs):
1480+
def f(x, a, b, c=3):
1481+
return x.sum() + (a + b) / c
1482+
1483+
df = pd.DataFrame([[1, 2], [3, 4]])
1484+
1485+
if axis == 0:
1486+
expected = pd.Series([5.0, 7.0])
1487+
else:
1488+
expected = pd.Series([4.0, 8.0])
1489+
1490+
result = df.agg(f, axis, *args, **kwargs)
1491+
1492+
tm.assert_series_equal(result, expected)
1493+
14661494
@pytest.mark.parametrize("num_cols", [2, 3, 5])
14671495
def test_frequency_is_original(self, num_cols):
14681496
# GH 22150

0 commit comments

Comments
 (0)