Description
I am using pandas.eval on a boolean series with missing data.
To do this I use an indexer to mark non-null values and .loc to only apply .eval on the rows with non-missing data.
Applying the logical not operator using the expression ~bool or not(bool) returns -1 or -2.
I understand that this is because my boolean series is casted as object type because of the missing values, but I am wondering :
- Why the -1 and -2 output ?
- What would be the proper way to use
.evalon a boolean series with missing data ?
Example
Here is a reproducible example using pandas 0.20.3.
df = pd.DataFrame({'bool': [True, False, None]})
bool
0 True
1 False
2 None
indexer = ~pd.isnull(df['bool'])
0 True
1 True
2 False
Name: bool, dtype: bool
df.loc[indexer].eval('~bool')
0 -2
1 -1
Name: bool, dtype: object