hgrecco / pint-pandas

Pandas support for pint
Other
166 stars 41 forks source link

PintArray needs _accumulate method for Pandas 2.0 (for cumsum) #170

Closed MichaelTiemannOSC closed 1 year ago

MichaelTiemannOSC commented 1 year ago

This new code in pandas/core/generic.py causes grief for pint-pandas:

11053           def block_accum_func(blk_values):
11054               values = blk_values.T if hasattr(blk_values, "T") else blk_values
11055   
11056               result: np.ndarray | ExtensionArray
11057               if isinstance(values, ExtensionArray):
11058 ->                    result = values._accumulate(name, skipna=skipna, **kwargs)
11059               else:
11060                   result = nanops.na_accum_func(values, func, skipna=skipna)
11061   
11062               result = result.T if hasattr(result, "T") else result
11063               return result

It's great that Pandas is expanding the implementation of ExtensionArrays, but Pint-Pandas needs to keep up by implementing an _accumulate function in PintPandas. That _accumulate function should implement cumsum, cumprod, and who knows what else.

coroa commented 1 year ago

It's a bit frustrating that this is the case, since their documentation states clearly:

One can (emphasis mine) implement methods to handle array accumulations or reductions.

  • _accumulate
  • _reduce

ie. this is a pandas doc or implementation bug.