pandas-dev/pandas · error · ValueError

No accumulation for {func} implemented on BaseMaskedArray

Error message

No accumulation for {func} implemented on BaseMaskedArray

What it means

Raised by _cum_func in datetimelike_accumulations.py:78 as a ValueError when an unsupported accumulation function is dispatched on a datetimelike BaseMaskedArray. The internal _cum_func only knows three numpy accumulators (np.cumsum, np.maximum.accumulate, np.minimum.accumulate); anything else hits the KeyError -> ValueError path. This is an internal dispatch guard - end users normally only reach it through cumsum/cummin/cummax on the supported dtypes.

Source

Thrown at pandas/core/array_algos/datetimelike_accumulations.py:78

    Accumulations for 1D datetimelike arrays.

    Parameters
    ----------
    func : np.cumsum, np.maximum.accumulate, np.minimum.accumulate
    values : np.ndarray
        Numpy array with the values (can be of any dtype that support the
        operation). Values is changed is modified inplace.
    skipna : bool, default True
        Whether to skip NA.
    """
    try:
        fill_value = {
            np.maximum.accumulate: np.iinfo(np.int64).min,
            np.cumsum: 0,
            np.minimum.accumulate: np.iinfo(np.int64).max,
        }[func]
    except KeyError as err:
        raise ValueError(
            f"No accumulation for {func} implemented on BaseMaskedArray"
        ) from err

    mask = isna(values)
    y = values.view("i8")
    y[mask] = fill_value

    if not skipna:
        mask = np.maximum.accumulate(mask)

    # GH 57956
    result = func(y, axis=0)
    if func is np.cumsum:
        # GH#66551: cummin/cummax cannot leave the range, cumsum can
        _check_cumsum_overflow(y, result, mask)
    result[mask] = iNaT

    if values.dtype.kind in "mM":

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Use only cumsum, cummin, or cummax on datetime64/timedelta64 Series - these are the implemented accumulations.
  2. If you need cumprod on numeric data, ensure the array is a numeric dtype (int/float) rather than datetimelike.
  3. For ExtensionArray authors: register the accumulation in the dispatch table or override the cum method on your array class.

Example fix

// before
s = pd.Series(pd.to_timedelta([1,2,3]))
# internal dispatch with np.cumprod reaches _cum_func
// after
s = pd.Series([1,2,3])  # plain numeric
s.cumprod()
Defensive patterns

Strategy: validation

Validate before calling

import numpy as np
_ALLOWED = {np.cumsum, np.maximum.accumulate, np.minimum.accumulate}
if func not in _ALLOWED:
    raise ValueError(f'{func} is not implemented for datetimelike accumulations; use cumsum/cummin/cummax')

Type guard

def supported_datetimelike_cum(func) -> bool:
    import numpy as np
    return func in {np.cumsum, np.maximum.accumulate, np.minimum.accumulate}

Prevention

When it happens

Trigger: Internally calling _cum_func(np.cumprod, datetimelike_values) or any accumulation not in {cumsum, max.accumulate, min.accumulate} on a datetime64/timedelta64 array. Hit at datetimelike_accumulations.py:71-80 when func is not in the supported dict.

Common situations: Third-party ExtensionArray subclasses routing an unsupported cum func through the datetimelike accumulator; calling cumprod on a timedelta Series (pandas usually blocks this earlier, but a custom path can reach _cum_func); version changes that add new accumulation entry points before updating the dispatch table.

Related errors


AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07). Data as JSON: /api/errors/c436b2beb515c682. Report an issue: GitHub.