pandas-dev/pandas · error · NotImplementedError

No masked accumulation defined for dtype

Error message

No masked accumulation defined for dtype {values.dtype.type}

What it means

NotImplementedError raised in masked_accumulations when the values array has a dtype kind outside float (f), signed/unsigned int (iu), or bool (b). Masked numeric accumulations are only defined for those kinds; anything else (complex, object, etc.) is rejected before computing.

Solutions

  1. Cast the array to a supported dtype (float/int/bool) before accumulating.
  2. Implement accumulation directly on the ExtensionArray rather than routing through masked_accumulations.
Defensive patterns

Strategy: validation

Validate before calling

import numpy as np
def safe_masked_accum(values, func):
    if values.dtype.kind not in 'fiub':
        values = values.astype('float64')
    return func(values)

Type guard

def is_supported_numeric_dtype(arr) -> bool:
    return arr.dtype.kind in 'fiub'

Try / catch

try:
    func(values)
except NotImplementedError as e:
    if 'No masked accumulation' in str(e):
        func(values.astype('float64'))
    else:
        raise

Prevention

When it happens

Trigger: Internal dispatch: calling _masked_accumulations / cumsum / cumprod on a masked array of unsupported dtype (e.g. complex128).

Common situations: Building custom ExtensionArray subtypes and routing their cum ops through the masked accumulator path with an unusual dtype.

Related errors


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

Appendix: source

Thrown at pandas/core/array_algos/masked_accumulations.py:52

        Numpy array with the values (can be of any dtype that support the
        operation).
    mask : np.ndarray
        Boolean numpy array (True values indicate missing values).
    skipna : bool, default True
        Whether to skip NA.
    """
    dtype_info: np.iinfo | np.finfo
    if values.dtype.kind == "f":
        dtype_info = np.finfo(values.dtype.type)
    elif values.dtype.kind in "iu":
        dtype_info = np.iinfo(values.dtype.type)
    elif values.dtype.kind == "b":
        # Max value of bool is 1, but since we are setting into a boolean
        # array, 255 is fine as well. Min value has to be 0 when setting
        # into the boolean array.
        dtype_info = np.iinfo(np.uint8)
    else:
        raise NotImplementedError(
            f"No masked accumulation defined for dtype {values.dtype.type}"
        )
    try:
        fill_value = {
            np.cumprod: 1,
            np.maximum.accumulate: dtype_info.min,
            np.cumsum: 0,
            np.minimum.accumulate: dtype_info.max,
        }[func]
    except KeyError as err:
        raise NotImplementedError(
            f"No accumulation for {func} implemented on BaseMaskedArray"
        ) from err

    values[mask] = fill_value

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

View on GitHub (pinned to 3b7651241d)