pandas-dev/pandas · error · TypeError
operation '{name}' not supported for dtype '{self.dtype}'
Error message
operation '{name}' not supported for dtype '{self.dtype}' What it means
StringArray._accumulate supports cumsum, cummin, cummax but explicitly forbids cumprod, raising TypeError. A cumulative product of strings is undefined, so the operation is rejected up front rather than producing garbage.
Source
Thrown at pandas/core/arrays/string_.py:1010
- cumsum
- cumprod
skipna : bool, default True
If True, skip NA values.
**kwargs
Additional keyword arguments passed to the accumulation function.
Currently, there is no supported kwarg.
Returns
-------
array
Raises
------
NotImplementedError : subclass does not define accumulations
"""
if name == "cumprod":
msg = f"operation '{name}' not supported for dtype '{self.dtype}'"
raise TypeError(msg)
# We may need to strip out trailing NA values
tail: np.ndarray | None = None
na_mask: np.ndarray | None = None
ndarray = self._ndarray
np_func = {
"cumsum": np.cumsum,
"cummin": np.minimum.accumulate,
"cummax": np.maximum.accumulate,
}[name]
if self._hasna:
na_mask = cast("npt.NDArray[np.bool_]", isna(ndarray))
if np.all(na_mask):
return type(self)(ndarray, dtype=self.dtype)
if skipna:
if name == "cumsum":
ndarray = np.where(na_mask, "", ndarray)View on GitHub (pinned to 71959b8cb9)
Solutions
- Do not call cumprod on string data.
- Convert numeric strings first: s.astype(float).cumprod().
- Exclude string columns from cumprod via select_dtypes.
Example fix
// before string_series.cumprod() // after string_series.astype(float).cumprod()
Defensive patterns
Strategy: validation
Validate before calling
if name == 'cumprod':
raise TypeError('cumprod is not supported for string dtype') Type guard
def is_supported_accumulation(name: str) -> bool:
return name in {'cumsum', 'cummin', 'cummax'} Prevention
- Never call cumprod on string data.
- Convert numeric strings via astype(float) before cumulative product.
- Exclude string columns from generic cumprod pipelines.
When it happens
Trigger: Calling string_series.cumprod(), or df.cumprod() on a DataFrame that includes a string column, or any accumulation pipeline that runs cumprod across all columns.
Common situations: Generic df.cumprod() calls; accumulation utilities applied uniformly; mistakenly treating string-encoded numbers as numeric without conversion.
Related errors
- Cannot change data-type for string array.
- Invalid value '{value}' for dtype '{self.dtype}'. Value shou
- Invalid value for dtype 'str'. Value should be a string or m
- Cannot perform reduction '{name}' with string dtype
- {func_name} requires a Series, Index, ExtensionArray, np.nda
AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07).
Data as JSON: /api/errors/cc1d8790f122443a.
Report an issue: GitHub.