Skip to content

Commit 3dc222d

Browse files
lithomas1jorisvandenbossche
authored andcommitted
pick out stringarray keepdims changes from #59234
1 parent baefc5c commit 3dc222d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

pandas/core/arrays/string_.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,13 @@ def astype(self, dtype, copy: bool = True):
736736
return super().astype(dtype, copy)
737737

738738
def _reduce(
739-
self, name: str, *, skipna: bool = True, axis: AxisInt | None = 0, **kwargs
739+
self,
740+
name: str,
741+
*,
742+
skipna: bool = True,
743+
keepdims: bool = False,
744+
axis: AxisInt | None = 0,
745+
**kwargs,
740746
):
741747
if self.dtype.na_value is np.nan and name in ["any", "all"]:
742748
if name == "any":
@@ -745,8 +751,10 @@ def _reduce(
745751
return nanops.nanall(self._ndarray, skipna=skipna)
746752

747753
if name in ["min", "max"]:
748-
return getattr(self, name)(skipna=skipna, axis=axis)
749-
754+
result = getattr(self, name)(skipna=skipna, axis=axis)
755+
if keepdims:
756+
return self._from_sequence([result], dtype=self.dtype)
757+
return result
750758
raise TypeError(f"Cannot perform reduction '{name}' with string dtype")
751759

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

0 commit comments

Comments
 (0)