Skip to content

Commit 897afec

Browse files
authored
CLN: Require ExtensionArray._reduce(keepdims=) (pandas-dev#58739)
1 parent b3d1805 commit 897afec

File tree

3 files changed

+2
-25
lines changed

3 files changed

+2
-25
lines changed

doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ Removal of prior version deprecations/changes
221221
- :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`)
222222
- :func:`to_datetime` with a ``unit`` specified no longer parses strings into floats, instead parses them the same way as without ``unit`` (:issue:`50735`)
223223
- :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`)
224+
- :meth:`ExtensionArray._reduce` now requires a ``keepdims: bool = False`` parameter in the signature (:issue:`52788`)
224225
- :meth:`Series.dt.to_pydatetime` now returns a :class:`Series` of :py:class:`datetime.datetime` objects (:issue:`52459`)
225226
- :meth:`SeriesGroupBy.agg` no longer pins the name of the group to the input passed to the provided ``func`` (:issue:`51703`)
226227
- All arguments except ``name`` in :meth:`Index.rename` are now keyword only (:issue:`56493`)

pandas/core/arrays/base.py

-6
Original file line numberDiff line numberDiff line change
@@ -1933,12 +1933,6 @@ def _reduce(
19331933
keepdims : bool, default False
19341934
If False, a scalar is returned.
19351935
If True, the result has dimension with size one along the reduced axis.
1936-
1937-
.. versionadded:: 2.1
1938-
1939-
This parameter is not required in the _reduce signature to keep backward
1940-
compatibility, but will become required in the future. If the parameter
1941-
is not found in the method signature, a FutureWarning will be emitted.
19421936
**kwargs
19431937
Additional keyword arguments passed to the reduction function.
19441938
Currently, `ddof` is the only supported kwarg.

pandas/core/frame.py

+1-19
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
Sequence,
2222
)
2323
import functools
24-
from inspect import signature
2524
from io import StringIO
2625
import itertools
2726
import operator
@@ -11408,28 +11407,11 @@ def func(values: np.ndarray):
1140811407
# We only use this in the case that operates on self.values
1140911408
return op(values, axis=axis, skipna=skipna, **kwds)
1141011409

11411-
dtype_has_keepdims: dict[ExtensionDtype, bool] = {}
11412-
1141311410
def blk_func(values, axis: Axis = 1):
1141411411
if isinstance(values, ExtensionArray):
1141511412
if not is_1d_only_ea_dtype(values.dtype):
1141611413
return values._reduce(name, axis=1, skipna=skipna, **kwds)
11417-
has_keepdims = dtype_has_keepdims.get(values.dtype)
11418-
if has_keepdims is None:
11419-
sign = signature(values._reduce)
11420-
has_keepdims = "keepdims" in sign.parameters
11421-
dtype_has_keepdims[values.dtype] = has_keepdims
11422-
if has_keepdims:
11423-
return values._reduce(name, skipna=skipna, keepdims=True, **kwds)
11424-
else:
11425-
warnings.warn(
11426-
f"{type(values)}._reduce will require a `keepdims` parameter "
11427-
"in the future",
11428-
FutureWarning,
11429-
stacklevel=find_stack_level(),
11430-
)
11431-
result = values._reduce(name, skipna=skipna, **kwds)
11432-
return np.array([result])
11414+
return values._reduce(name, skipna=skipna, keepdims=True, **kwds)
1143311415
else:
1143411416
return op(values, axis=axis, skipna=skipna, **kwds)
1143511417

0 commit comments

Comments
 (0)