Skip to content

Commit

Permalink
pick out stringarray keepdims changes from #59234
Browse files Browse the repository at this point in the history
  • Loading branch information
lithomas1 authored and jorisvandenbossche committed Oct 9, 2024
1 parent baefc5c commit 3dc222d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pandas/core/arrays/string_.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,13 @@ def astype(self, dtype, copy: bool = True):
return super().astype(dtype, copy)

def _reduce(
self, name: str, *, skipna: bool = True, axis: AxisInt | None = 0, **kwargs
self,
name: str,
*,
skipna: bool = True,
keepdims: bool = False,
axis: AxisInt | None = 0,
**kwargs,
):
if self.dtype.na_value is np.nan and name in ["any", "all"]:
if name == "any":
Expand All @@ -745,8 +751,10 @@ def _reduce(
return nanops.nanall(self._ndarray, skipna=skipna)

if name in ["min", "max"]:
return getattr(self, name)(skipna=skipna, axis=axis)

result = getattr(self, name)(skipna=skipna, axis=axis)
if keepdims:
return self._from_sequence([result], dtype=self.dtype)
return result
raise TypeError(f"Cannot perform reduction '{name}' with string dtype")

def _wrap_reduction_result(self, axis: AxisInt | None, result) -> Any:
Expand Down

0 comments on commit 3dc222d

Please sign in to comment.