Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Pandas treats NaN and None differently when multiplying booleans #2798

Closed
darindillon opened this issue Feb 5, 2013 · 1 comment
Closed
Labels
Dtype Conversions Unexpected or buggy dtype conversions
Milestone

Comments

@darindillon
Copy link

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

@jreback
Copy link
Contributor

jreback commented Mar 22, 2013

You have different dtypes for these series.

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

@jreback jreback closed this as completed Mar 28, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions
Projects
None yet
Development

No branches or pull requests

2 participants