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
In [2]: import pandas as pd
In [3]: a = pd.Series([True,False,True])
In [4]: a
Out[4]:
0 True
1 False
2 True
dtype: bool
In [6]: a[0] = pd.np.nan
In [7]: a
Out[7]:
0 NaN
1 0.0
2 1.0
dtype: float64
Expected Output
based on type promotions mentioned here I would expect the series to get promoted to object to allow for NaNs.
When introducing NAs into an existing Series or DataFrame via reindex or some other means, boolean and integer types will be promoted to a different dtype in order to store the NAs. These are summarized by this table:
In [7]: a
Out[7]:
0 NaN
1 False
2 True
dtype: object
yeah that should coerce to object. Right now we are promoting a boolean with nulls -> float64
this is somewhat deep in there. need to look inside core/internals/Block.setitem. where _maybe_promote is called. Bools have not gotten much love lately.
Though to be fair we do this similar to how we do ints with NA's, meaning we cast to floats.
So not sure how much this is relied upon in the real world.
jreback
changed the title
Series bool type not promoted to object when introducing NaNs
BUG/COMPAT: Series bool type not promoted to object when introducing NaNs
Apr 30, 2016
This looks to work on master now. Could use a test
In [3]: In [2]: import pandas as pd
...:
...: In [3]: a = pd.Series([True,False,True])
In [4]: a[0] = np.nan
In [5]: a
Out[5]:
0 NaN
1 False
2 True
dtype: object
Code Sample, a copy-pastable example if possible
Expected Output
based on type promotions mentioned here I would expect the series to get promoted to
object
to allow forNaN
s.output of
pd.show_versions()
The text was updated successfully, but these errors were encountered: