For the following test code, could someone explain why the contents of test1 and test2 differ for the third row (index 2)? I had code written a la test1 and wasted a few hours trying to figure out why the code wasn't working before re-writing a la test2 to solve it. Is it an order-of-operations thing within pandas for the one-liner used to generate test1?
import pandas as pd
# test data
dat1 = [1,1,2,1]
dat2 = ['a','b','c','d'] # only for building a multi-column DF, not otherwise used
dat3 = [False,False,True,False]
# build a dataframe
df = pd.DataFrame( data={ "Data1":dat1, "Data2":dat2})
# first test
test1 = df['Data1']==1 | pd.Series(dat3)
print('==test 1==')
print(test1)
# second test
tmp1 = df['Data1']==1
tmp2 = pd.Series(dat3)
test2 = tmp1 | tmp2
print('==test 2==')
print(test2)
The output is
==test 1==
0 True
1 True
2 False
3 True
dtype: bool
==test 2==
0 True
1 True
2 True
3 True
dtype: bool