Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v1.5.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ Fixed regressions
- Fixed regression causing an ``AttributeError`` during warning emitted if the provided table name in :meth:`DataFrame.to_sql` and the table name actually used in the database do not match (:issue:`48733`)
- Fixed :meth:`.DataFrameGroupBy.size` not returning a Series when ``axis=1`` (:issue:`48738`)
- Fixed Regression in :meth:`DataFrameGroupBy.apply` when user defined function is called on an empty dataframe (:issue:`47985`)
- Fixed regression in :meth:`DataFrame.apply` when passing non-zero ``axis`` via keyword argument (:issue:`48656`)
-

.. ---------------------------------------------------------------------------

Expand Down
5 changes: 3 additions & 2 deletions pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,11 @@ def apply_str(self) -> DataFrame | Series:
if callable(func):
sig = inspect.getfullargspec(func)
if self.axis != 0 and (
"axis" not in sig.args or f in ("corrwith", "mad", "skew")
("axis" not in sig.args and "axis" not in sig.kwonlyargs)
or f in ("corrwith", "mad", "skew")
):
raise ValueError(f"Operation {f} does not support axis=1")
elif "axis" in sig.args:
elif "axis" in sig.args or "axis" in sig.kwonlyargs:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to above

self.kwargs["axis"] = self.axis
return self._try_aggregate_string_function(obj, f, *self.args, **self.kwargs)

Expand Down
17 changes: 17 additions & 0 deletions pandas/tests/groupby/test_any_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,23 @@ def test_any_non_keyword_deprecation():
tm.assert_equal(result, expected)


def test_any_apply_keyword_non_zero_axis_regression():
# https://github.com/pandas-dev/pandas/issues/48656
df = DataFrame({"A": [1, 2], "B": [0, 2], "C": [0, 0]})
expected = df.any(axis=1)
result = df.apply("any", axis=1)
tm.assert_series_equal(result, expected)

msg = (
"In a future version of pandas all arguments of "
"DataFrame.any and Series.any will be keyword-only."
)
with tm.assert_produces_warning(FutureWarning, match=msg):
expected = df.any(1)
result = df.apply("any", 1)
tm.assert_series_equal(result, expected)


@pytest.mark.parametrize("bool_agg_func", ["any", "all"])
def test_bool_aggs_dup_column_labels(bool_agg_func):
# 21668
Expand Down