pandas-dev/pandas · error · TypeError
'{type(self).__name__}' with dtype {self.dtype} does not sup
Error message
'{type(self).__name__}' with dtype {self.dtype} does not support operation '{name}' What it means
ExtensionArray._reduce (base.py:2480) dispatches by looking up an attribute named `name` (e.g. 'sum', 'mean', 'median') on self; if no such method exists it raises TypeError stating the class+dtype does not support that operation. This is the generic reduction fallback used by Series.min/max/sum/mean/median/std/var/prod/sem/kurt/skew.
Source
Thrown at pandas/core/arrays/base.py:2480
Series.kurt : Return the kurtosis.
Series.skew : Return the skewness.
Examples
--------
>>> pd.array([1, 2, 3])._reduce("min")
np.int64(1)
>>> pd.array([1, 2, 3])._reduce("max")
np.int64(3)
>>> pd.array([1, 2, 3])._reduce("sum")
np.int64(6)
>>> pd.array([1, 2, 3])._reduce("mean")
np.float64(2.0)
>>> pd.array([1, 2, 3])._reduce("median")
np.float64(2.0)
"""
meth = getattr(self, name, None)
if meth is None:
raise TypeError(
f"'{type(self).__name__}' with dtype {self.dtype} "
f"does not support operation '{name}'"
)
if name != "count":
kwargs["skipna"] = skipna
result = meth(**kwargs)
if keepdims:
if name in ["min", "max"]:
result = self._from_sequence([result], dtype=self.dtype)
else:
result = np.array([result])
return result
def count(self):
"""
Count the number of non-NA values in the array.
View on GitHub (pinned to 71959b8cb9)
Solutions
- Pass numeric_only=True (or select numeric columns) so the reduction skips unsupported dtypes.
- Convert the Series to a supported numeric dtype before reducing: s.astype('Float64').mean().
- Implement the missing reduction method on your ExtensionArray subclass so _reduce can dispatch to it.
- Choose a reduction that the dtype supports (e.g. count/min/max instead of mean for non-numeric).
Example fix
# before
s = pd.Series(["1", "2"], dtype="string")
s.mean() # raises
# after
s.astype("Int64").mean() Defensive patterns
Strategy: validation
Validate before calling
def safe_reduce(s, name):
import pandas as pd
if not pd.api.types.is_numeric_dtype(s) and name not in ("count", "min", "max"):
raise TypeError(f"{s.dtype} does not support {name}")
return getattr(s, name)() Type guard
def supports_reduction(dtype, name) -> bool:
import pandas as pd
numeric_ops = {"sum","mean","median","prod","std","var","sem","kurt","skew"}
return name in ("count","min","max") or pd.api.types.is_numeric_dtype(dtype) or name not in numeric_ops Try / catch
try:
val = s.mean()
except TypeError as e:
if "does not support operation" in str(e):
val = s.astype("Float64").mean()
else:
raise Prevention
- Use numeric_only=True on DataFrame reductions
- Convert dtypes before reducing
- Check method exists on the dtype before calling
When it happens
Trigger: Calling an unsupported reduction on an EA-backed Series, e.g. s.median() on a string-dtype EA, s.prod() on a datetime EA, or s.kurt() on a boolean EA, where the EA lacks a method of that name.
Common situations: Applying df.mean(numeric_only=False) across heterogeneous columns; calling a statistical reduction on a non-numeric Series; using a custom EA that only implemented some reductions.
Related errors
- Encountered an NA value with skipna=False
- Cannot round dtype {self.dtype} as it is non-numeric
- `axis` must be fewer than the number of dimensions ({ndim})
- cannot diff {type(arr).__name__} on axis={axis}
- {type(arr).__name__} has no 'diff' method. Convert to a suit
AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07).
Data as JSON: /api/errors/cefedee36ffe1e6d.
Report an issue: GitHub.