Skip to content

Commit

Permalink
CLN: Require ExtensionArray._reduce(keepdims=) (pandas-dev#58739)
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke authored May 16, 2024
1 parent b3d1805 commit 897afec
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 25 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ Removal of prior version deprecations/changes
- :func:`read_excel`, :func:`read_json`, :func:`read_html`, and :func:`read_xml` no longer accept raw string or byte representation of the data. That type of data must be wrapped in a :py:class:`StringIO` or :py:class:`BytesIO` (:issue:`53767`)
- :func:`to_datetime` with a ``unit`` specified no longer parses strings into floats, instead parses them the same way as without ``unit`` (:issue:`50735`)
- :meth:`DataFrame.groupby` with ``as_index=False`` and aggregation methods will no longer exclude from the result the groupings that do not arise from the input (:issue:`49519`)
- :meth:`ExtensionArray._reduce` now requires a ``keepdims: bool = False`` parameter in the signature (:issue:`52788`)
- :meth:`Series.dt.to_pydatetime` now returns a :class:`Series` of :py:class:`datetime.datetime` objects (:issue:`52459`)
- :meth:`SeriesGroupBy.agg` no longer pins the name of the group to the input passed to the provided ``func`` (:issue:`51703`)
- All arguments except ``name`` in :meth:`Index.rename` are now keyword only (:issue:`56493`)
Expand Down
6 changes: 0 additions & 6 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1933,12 +1933,6 @@ def _reduce(
keepdims : bool, default False
If False, a scalar is returned.
If True, the result has dimension with size one along the reduced axis.
.. versionadded:: 2.1
This parameter is not required in the _reduce signature to keep backward
compatibility, but will become required in the future. If the parameter
is not found in the method signature, a FutureWarning will be emitted.
**kwargs
Additional keyword arguments passed to the reduction function.
Currently, `ddof` is the only supported kwarg.
Expand Down
20 changes: 1 addition & 19 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
Sequence,
)
import functools
from inspect import signature
from io import StringIO
import itertools
import operator
Expand Down Expand Up @@ -11408,28 +11407,11 @@ def func(values: np.ndarray):
# We only use this in the case that operates on self.values
return op(values, axis=axis, skipna=skipna, **kwds)

dtype_has_keepdims: dict[ExtensionDtype, bool] = {}

def blk_func(values, axis: Axis = 1):
if isinstance(values, ExtensionArray):
if not is_1d_only_ea_dtype(values.dtype):
return values._reduce(name, axis=1, skipna=skipna, **kwds)
has_keepdims = dtype_has_keepdims.get(values.dtype)
if has_keepdims is None:
sign = signature(values._reduce)
has_keepdims = "keepdims" in sign.parameters
dtype_has_keepdims[values.dtype] = has_keepdims
if has_keepdims:
return values._reduce(name, skipna=skipna, keepdims=True, **kwds)
else:
warnings.warn(
f"{type(values)}._reduce will require a `keepdims` parameter "
"in the future",
FutureWarning,
stacklevel=find_stack_level(),
)
result = values._reduce(name, skipna=skipna, **kwds)
return np.array([result])
return values._reduce(name, skipna=skipna, keepdims=True, **kwds)
else:
return op(values, axis=axis, skipna=skipna, **kwds)

Expand Down

0 comments on commit 897afec

Please sign in to comment.