hgrecco / pint-pandas

Pandas support for pint
Other
169 stars 42 forks source link

Grouping and Aggregating with NaN-values destroys `dtype` #117

Closed carlculator closed 1 year ago

carlculator commented 2 years ago
import pint
import numpy as np
import pandas as pd
from pint_pandas import PintArray

ureg = pint.get_application_registry()
p = PintArray(list(range(2)) + [np.nan], dtype=ureg.parse_units('m'))  # <PintArray> [0.0, 1.0, nan] Length: 3, dtype: pint[meter]
s = pd.Series(p)
s.groupby(level=0).sum()

# >>> 0    0.0 meter
# >>> 1    1.0 meter
# >>> 2            0
# >>> dtype: object 

I think the operation should keep the unit of the series intact.

andrewgsavage commented 1 year ago

fixed by #133