You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
I am facing this issue while building a pd.Series with pint dtype.
When float("nan") is alone, it remains float("nan").
When float("nan") is with other values, it is converted into pd.NA.
This is not evident printing the series (the formatting shows always nan), but values or tolist() reveal the difference.
importpintasptimportpandasaspdimportpint_pandas# case 1: float nan aloneprint(pd.Series([float("nan")], dtype="pint[MW]").tolist())
# gives: [<Quantity(nan, 'megawatt')>]# case 2: float nan with other valuesprint(pd.Series([float("nan"), 0.0], dtype="pint[MW]").tolist())
# gives: [<Quantity(<NA>, 'megawatt')>, <Quantity(0.0, 'megawatt')>]
I supposed that float("nan") was the default value meaning "not set magnitude".
The fact that nan is converted to pd.NA based on other values in the series looks bit tricky to me: is it intended?
I am looking a way to keep not-set values consistent (either all float("nan"), or all pd.NA), but:
Tying to convert pd.NA to float("nan") has no effect.
If I try to convert float("nan") to pd.NA I get ValueError.
# test 1: trying to convert pd.NA to nans=pd.Series([float("nan"), 0.0], dtype="pint[MW]")
print(s.tolist())
# gives: [<Quantity(<NA>, 'megawatt')>, <Quantity(0, 'megawatt')>]print(s.fillna(float("nan")).tolist())
# gives the same: [<Quantity(<NA>, 'megawatt')>, <Quantity(0, 'megawatt')>]# test 2: trying to convert nan to pd.NAs=pd.Series([float("nan")], dtype="pint[MW]")
print(s.tolist())
# gives: [<Quantity(nan, 'megawatt')>]s.fillna(pd.NA)
# gives: ValueError: float() argument must be a string or a real number, not 'NAType'
Have an option to change the conversion to some other dtype
Have an option to prevent conversion, allowing any dtype as the underlying data dtype. In this case, specify the underlying dtype in the pint dtype, eg 'pint[MW][Float64]'
Hello,
I am facing this issue while building a
pd.Series
with pint dtype.float("nan")
is alone, it remainsfloat("nan")
.float("nan")
is with other values, it is converted intopd.NA
.This is not evident printing the series (the formatting shows always
nan
), butvalues
ortolist()
reveal the difference.I supposed that
float("nan")
was the default value meaning "not set magnitude".The fact that nan is converted to
pd.NA
based on other values in the series looks bit tricky to me: is it intended?I am looking a way to keep not-set values consistent (either all
float("nan")
, or allpd.NA
), but:pd.NA
tofloat("nan")
has no effect.float("nan")
topd.NA
I getValueError
.The text was updated successfully, but these errors were encountered: