Skip to content

CLN: consistent EA._reduce signatures #35308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from all 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: 1 addition & 1 deletion pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ def _concat_same_type(
# of objects
_can_hold_na = True

def _reduce(self, name, skipna=True, **kwargs):
def _reduce(self, name: str, skipna: bool = True, **kwargs):
"""
Return a scalar result of performing the reduction operation.

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2076,11 +2076,11 @@ def _reverse_indexer(self) -> Dict[Hashable, np.ndarray]:
return result

# reduction ops #
def _reduce(self, name, axis=0, **kwargs):
def _reduce(self, name: str, skipna: bool = True, **kwargs):
func = getattr(self, name, None)
if func is None:
raise TypeError(f"Categorical cannot perform the operation {name}")
return func(**kwargs)
return func(skipna=skipna, **kwargs)

@deprecate_kwarg(old_arg_name="numeric_only", new_arg_name="skipna")
def min(self, skipna=True, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -1552,7 +1552,7 @@ def __isub__(self, other):
# --------------------------------------------------------------
# Reductions

def _reduce(self, name, axis=0, skipna=True, **kwargs):
def _reduce(self, name: str, skipna: bool = True, **kwargs):
op = getattr(self, name, None)
if op:
return op(skipna=skipna, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/sparse/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ def nonzero(self):
# Reductions
# ------------------------------------------------------------------------

def _reduce(self, name, skipna=True, **kwargs):
def _reduce(self, name: str, skipna: bool = True, **kwargs):
method = getattr(self, name, None)

if method is None:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/string_.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def astype(self, dtype, copy=True):

return super().astype(dtype, copy)

def _reduce(self, name, skipna=True, **kwargs):
def _reduce(self, name: str, skipna: bool = True, **kwargs):
if name in ["min", "max"]:
return getattr(self, name)(skipna=skipna)

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/extension/arrow/arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@ def _concat_same_type(cls, to_concat):
def __invert__(self):
return type(self).from_scalars(~self._data.to_pandas())

def _reduce(self, method, skipna=True, **kwargs):
def _reduce(self, name: str, skipna: bool = True, **kwargs):
if skipna:
arr = self[~self.isna()]
else:
arr = self

try:
op = getattr(arr, method)
op = getattr(arr, name)
except AttributeError as err:
raise TypeError from err
return op(**kwargs)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/extension/decimal/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def _formatter(self, boxed=False):
def _concat_same_type(cls, to_concat):
return cls(np.concatenate([x._data for x in to_concat]))

def _reduce(self, name, skipna=True, **kwargs):
def _reduce(self, name: str, skipna: bool = True, **kwargs):

if skipna:
# If we don't have any NAs, we can ignore skipna
Expand Down