Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Delegate to min and max methods
  • Loading branch information
Daniel Saxton authored and Daniel Saxton committed Feb 14, 2020
commit 4a61b81f16f64a0b8d3a1f8a1de4c79263b23e62
21 changes: 13 additions & 8 deletions pandas/core/arrays/string_.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,17 +274,22 @@ def astype(self, dtype, copy=True):
return super().astype(dtype, copy)

def _reduce(self, name, skipna=True, **kwargs):
if name in ["min", "max", "sum"]:
na_mask = isna(self)
if not na_mask.any():
return getattr(self, name)(skipna=False, **kwargs)
elif skipna:
return getattr(self[~na_mask], name)(skipna=False, **kwargs)
else:
return libmissing.NA
if name in ["min", "max"]:
return getattr(self, name)(
skipna=skipna, **kwargs
)

raise TypeError(f"Cannot perform reduction '{name}' with string dtype")

def min(self, axis=None, out=None, keepdims=False, skipna=True):
nv.validate_min((), dict(out=out, keepdims=keepdims))
return nanops.nanmin(self._ndarray, axis=axis, skipna=skipna)

def max(self, axis=None, out=None, keepdims=False, skipna=True):
nv.validate_max((), dict(out=out, keepdims=keepdims))
return nanops.nanmax(self._ndarray, axis=axis, skipna=skipna)


def value_counts(self, dropna=False):
from pandas import value_counts

Expand Down