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 in bool type series logical AND operation #13538

Closed
stsouko opened this issue Jun 30, 2016 · 3 comments · Fixed by #13894
Closed

bug in bool type series logical AND operation #13538

stsouko opened this issue Jun 30, 2016 · 3 comments · Fixed by #13894
Labels
Milestone

Comments

@stsouko
Copy link

stsouko commented Jun 30, 2016

Code Sample, a copy-pastable example if possible

s1=pd.Series([True,False,True,True])
s2=pd.Series([True,True,False])

s1.index=pd.MultiIndex.from_tuples( [(0, 2), (1, 1), (1, 2), (2, 1)],names=['st', 'at'])
s2.index=pd.Index([0,1,2], name='st')

ds1=pd.DataFrame(s1)
ds2=pd.DataFrame(s2)

s3=pd.Series([True,False,True])
s4=pd.Series([True,True,False])

Expected Output

st  at
0   2      True
1   1     False
1   2      True
2   1     False
dtype: bool

For series, * and & give different result:

In: s1 & s2
Out: 
st  at
0   2     False
1   1     False
1   2     False
2   1     False
dtype: bool

In: s1 * s2
Out: 
st  at
0   2      True
1   1     False
1   2      True
2   1     False
dtype: bool

BUT for dataframes they give the same:

In: ds1 * ds2
Out: 
           0
st at       
0  2    True
1  1   False
1  2    True
2  1   False

In: ds1 & ds2
Out: 
           0
st at       
0  2    True
1  1   False
1  2    True
2  1   False

and last for series with single index, also both s3 & s4 or s3 * s4 give:

0     True
1    False
2    False
dtype: bool

output of pd.show_versions()

pandas: 0.18.1

@jorisvandenbossche
Copy link
Member

It seems there is going something wrong with the alignment.

Also, if you switch the position, you get an error:

In [43]: s2 & s1
...
ValueError: Buffer dtype mismatch, expected 'Python object' but got 'long long'

@jreback
Copy link
Contributor

jreback commented Jun 30, 2016

this is a duplicate of #1134

you need to join before you do this - it's not s well defined operation as specified

@jorisvandenbossche
Copy link
Member

I think it is a slightly different issue

Consider those serieses:

In [84]: s1 = pd.Series([True,False,True])

In [85]: s2 = pd.Series([True,True,False])

In [86]: s2b = pd.Series([True,True,False], index=[1,2,3])

The issue in #1134 is that the index is ignored, so using s2 or s2b gives the same:

In [87]: s1 == s2
Out[87]:
0     True
1    False
2    False
dtype: bool

In [88]: s1 == s2b
Out[88]:
0     True
1    False
2    False
dtype: bool

But in this case, s2 and s2b do not give the same:

In [89]: s1 & s2
Out[89]:
0     True
1    False
2    False
dtype: bool

In [90]: s1 & s2b
Out[90]:
0    False
1    False
2     True
dtype: bool

In the case of non-identical index, the result is also not the same as when the index is ignored:

In [91]: s1.values & s2b.values
Out[91]: array([ True, False, False], dtype=bool)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants