Pandas query function with subexpressions that do not include column name

I am having problems with the pandas query function, where the subexpressions do not contain any of the columns of the frame. I expect the following to give [True, False], but actually he answers [False, True]:

df = pd.DataFrame( {'col1':[1,0]} )

col1
0     1
1     0

external_var = 'yes'
df.eval( '(@external_var == "yes") == col1' )

0     False
1     True

The problem does not seem to be related to use external_var, because

df.eval( '("yes" == "yes") == col1' ) gives the same unexpected result.

context

- , -. ( external_var), . , , , , . , - PandasExprVisitor.

, , , , , , , .

jupyter pandas 0.16.2 numexpr 2.4.3.

+4
1

(GH11044) , , ​​ Release.

In [9]: df.eval( '("yes" == "yes")')
Out[9]: False
+1

Source: https://habr.com/ru/post/1606588/


All Articles