pandas-dev/pandas · error · NotImplementedError
cannot perform with type
Error message
cannot perform {name} with type {self.dtype} What it means
_accumulate dispatches cumulative reductions (cumsum, cumprod, cummin, cummax, cummax). The base ExtensionArray provides no default — it raises NotImplementedError naming the requested operation and the array's dtype, because accumulation semantics (especially NA propagation and casting) are dtype-specific. Subclasses opt in.
Solutions
- Scope the cumulative op to supported columns: df.select_dtypes(include='number').cumsum().
- If you own the EA, implement _accumulate handling the supported names and NA propagation per your dtype rules.
- Convert the column to a backed numpy dtype before accumulating, accepting loss of NA semantics.
Example fix
// before
df.cumsum() # NotImplementedError: cannot perform cumsum with type ...
// after
df.select_dtypes(include='number').cumsum()
# or for the specific column
series.astype('float64').cumsum() Defensive patterns
Strategy: fallback
Validate before calling
supported = {'cumsum','cumprod','cummin','cummax'}
from pandas.api.extensions import ExtensionArray
if name in supported and getattr(type(arr), '_accumulate', None) is ExtensionArray._accumulate:
raise NotImplementedError(f'{type(arr).__name__} does not support {name}') Type guard
def supports_accumulate(cls) -> bool:
return getattr(cls, '_accumulate', None) is not ExtensionArray._accumulate Try / catch
try:
out = series.cumsum()
except NotImplementedError:
out = series.astype('float64').cumsum() Prevention
- Restrict cumulative ops to numeric columns via select_dtypes.
- Implement _accumulate on the EA for supported names with explicit NA handling.
- Cast to a numpy dtype before accumulating when NA semantics are not required.
When it happens
Trigger: Calling Series.cumsum / cummax / cummin / cumprod on a Series backed by a custom ExtensionArray that did not override _accumulate. Reached via df.cumsum() on a column of that dtype.
Common situations: Applying cumulative reductions across a mixed-dtype frame where one custom EA column lacks _accumulate. Third-party dtype that implements instantaneous reductions (_reduce) but not cumulative ones.
Related errors
- Default 'empty' implementation is invalid for dtype=
- {dtype}
- function is not implemented for this dtype
- does not implement interpolate
- can only convert an array of size 1 to a Python scalar
AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11).
Data as JSON: /api/errors/1e61ee7fa869f23a.
Report an issue: GitHub.
Appendix: source
Thrown at pandas/core/arrays/base.py:2411
NotImplementedError : subclass does not define accumulations
See Also
--------
api.extensions.ExtensionArray._concat_same_type : Concatenate multiple
array of this dtype.
api.extensions.ExtensionArray.view : Return a view on the array.
api.extensions.ExtensionArray._explode : Transform each element of
list-like to a row.
Examples
--------
>>> arr = pd.array([1, 2, 3])
>>> arr._accumulate(name="cumsum")
<IntegerArray>
[1, 3, 6]
Length: 3, dtype: Int64
"""
raise NotImplementedError(f"cannot perform {name} with type {self.dtype}")
def _reduce(
self, name: str, *, skipna: bool = True, keepdims: bool = False, **kwargs
):
"""
Return a scalar result of performing the reduction operation.
This method dispatches to the appropriate reduction method (e.g.,
sum, mean, min, max) based on the `name` parameter and returns
the result.
Parameters
----------
name : str
Name of the function, supported values are:
{ any, all, min, max, sum, mean, median, prod,
std, var, sem, kurt, skew }.
skipna : bool, default TrueView on GitHub (pinned to 3b7651241d)