pandas-dev/pandas · error · TypeError

' ' with dtype does not support operation

Error message

'{type(self).__name__}' with dtype {self.dtype} does not support operation '{name}'

What it means

_reduce looks up the reduction by name via getattr(self, name); if the EA subclass has no attribute matching the requested reduction (e.g. 'sum', 'mean', 'median', 'prod', 'std', 'sem', 'var', 'kurt', 'skew', 'min', 'max'), it raises TypeError naming the class, dtype, and unsupported operation. The docstring's Raises section documents this as the contract for subclasses that do not define a given operation.

Solutions

  1. Select only columns whose dtype supports the reduction before applying: df.select_dtypes(include='number').mean().
  2. If you own the EA, implement the method by the exact name pandas dispatches (e.g. def sum(self, *, skipna, ...)).
  3. Catch the TypeError in a per-column reduction loop and skip/record the unsupported column.

Example fix

// before
df.mean()  # TypeError: 'MyArray' with dtype ... does not support operation 'mean'

// after
df.select_dtypes(include='number').mean()
Defensive patterns

Strategy: validation

Validate before calling

name = 'mean'  # the reduction you plan to call
if not callable(getattr(arr, name, None)):
    raise TypeError(f'{type(arr).__name__} does not support {name}')
_ = arr._reduce(name)

Type guard

def supports_reduction(arr, name: str) -> bool:
    return callable(getattr(arr, name, None))

Try / catch

try:
    val = series._reduce('mean')
except TypeError:
    val = series.astype('float64').mean()

Prevention

When it happens

Trigger: Calling Series.sum/mean/median/etc. (or df.<reduction>()) on a Series backed by a custom EA that does not implement the requested reduction method. The dispatch resolves to ExtensionArray._reduce(name) which finds no attribute and raises TypeError.

Common situations: A custom string/categorical-like dtype where arithmetic reductions are meaningless but the user invoked Series.mean. Mixed-dtype frames where one column's EA lacks a reduction. A reduction name typo or an unsupported custom reduction name.

Related errors


AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11). Data as JSON: /api/errors/cefedee36ffe1e6d. Report an issue: GitHub.

Appendix: 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 3b7651241d)