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
Using pandas 0.10.
Pandas throws error when multiplying a series with booleans and a series with None. However, it works fine when you reverse the order. Also, it works fine if you use NaN instead of None. But isn't pandas supposed to treat NaN and None interchangably?
In [9]: nans
Out[9]:
0 NaN
1 NaN
dtype: float64
In [10]: nones
Out[10]:
0 None
1 None
dtype: object
In [11]: bools
Out[11]:
0 True
1 False
dtype: bool
Nones are are not treated like np.nan, they are an object type (like a string).
They will be coered into np.nan in a constructor if there are other types.
n [12]: Series([None,1])
Out[12]:
0 NaN
1 1
dtype: float64
however in your example, they are left as object because pandas doesn't know what to do with them (similary to how mixed types are handled)
The return type for a binary operation (e.g. * here), is whatever numpy says it is, which is the first type, maybe upcasted (e.g. an int * float == float type, unless the float is equiv to an int)
your last example blows up because the return type is bool, which you can't do any operations on except for comparison to other bool types
the bools * nans is a special case in numpy I think where you get NaN output, not sure why
Using pandas 0.10.
Pandas throws error when multiplying a series with booleans and a series with None. However, it works fine when you reverse the order. Also, it works fine if you use NaN instead of None. But isn't pandas supposed to treat NaN and None interchangably?
import pandas
import numpy as np
nans = pandas.Series([np.NaN, np.NaN])
nones = pandas.Series([None, None])
bools= pandas.Series([True,False])
x = nans * bools #works fine
x = bools * nans #works fine
x = nones * bools #works fine
x = bools * nones #ERROR! THIS BLOWS UP
The text was updated successfully, but these errors were encountered: