Dataframes of temperatures print nicely. PintArrays do not. Consider this code condensed from TestIssue21 of the Pint-Pandas testsuite (migrated from https://github.com/hgrecco/pint/issues/812)
import numpy as np
import pandas as pd
from pint_pandas import PintArray, PintType
ureg = PintType.ureg
q_a = ureg.Quantity(np.arange(5), ureg.Unit("degC"))
q_a = ureg.Quantity(np.arange(5)+ufloat(0,0.1), ureg.Unit("degC"))
q_b = ureg.Quantity(np.arange(6)+ufloat(0,0.1), ureg.Unit("degC"))
q_a_ = np.append(q_a, ufloat(np.nan, 0))
a = pd.Series(PintArray(q_a))
b = pd.Series(PintArray(q_b))
result = pd.concat([a, b], axis=1)
We can print q_a and a, but not PintArray(q_a) when units are degC. We can print all three when units are m.
The offender is the getitem method of PintArray, here:
if is_integer(item):
return self._data[item] * self.units # Should not use multiplication to create a quantity from magnitude and unit
Dataframes of temperatures print nicely. PintArrays do not. Consider this code condensed from TestIssue21 of the Pint-Pandas testsuite (migrated from https://github.com/hgrecco/pint/issues/812)
We can print
q_a
anda
, but notPintArray(q_a)
when units aredegC
. We can print all three when units arem
.The offender is the getitem method of PintArray, here: