@@ -479,11 +479,13 @@ def test_query_scope(self):
479
479
tm .assert_frame_equal (res , expected )
480
480
481
481
# no local variable c
482
- with pytest .raises (UndefinedVariableError ):
482
+ with pytest .raises (
483
+ UndefinedVariableError , match = "local variable 'c' is not defined"
484
+ ):
483
485
df .query ("@a > b > @c" , engine = engine , parser = parser )
484
486
485
487
# no column named 'c'
486
- with pytest .raises (UndefinedVariableError ):
488
+ with pytest .raises (UndefinedVariableError , match = "name 'c' is not defined" ):
487
489
df .query ("@a > b > c" , engine = engine , parser = parser )
488
490
489
491
def test_query_doesnt_pickup_local (self ):
@@ -494,7 +496,7 @@ def test_query_doesnt_pickup_local(self):
494
496
df = DataFrame (np .random .randint (m , size = (n , 3 )), columns = list ("abc" ))
495
497
496
498
# we don't pick up the local 'sin'
497
- with pytest .raises (UndefinedVariableError ):
499
+ with pytest .raises (UndefinedVariableError , match = "name 'sin' is not defined" ):
498
500
df .query ("sin > 5" , engine = engine , parser = parser )
499
501
500
502
def test_query_builtin (self ):
@@ -588,7 +590,7 @@ def test_nested_raises_on_local_self_reference(self):
588
590
df = DataFrame (np .random .randn (5 , 3 ))
589
591
590
592
# can't reference ourself b/c we're a local so @ is necessary
591
- with pytest .raises (UndefinedVariableError ):
593
+ with pytest .raises (UndefinedVariableError , match = "name 'df' is not defined" ):
592
594
df .query ("df > 0" , engine = self .engine , parser = self .parser )
593
595
594
596
def test_local_syntax (self ):
@@ -651,9 +653,9 @@ def test_query_undefined_local(self):
651
653
skip_if_no_pandas_parser (parser )
652
654
653
655
df = DataFrame (np .random .rand (10 , 2 ), columns = list ("ab" ))
654
- msg = "local variable 'c' is not defined"
655
-
656
- with pytest . raises ( UndefinedVariableError , match = msg ):
656
+ with pytest . raises (
657
+ UndefinedVariableError , match = "local variable 'c' is not defined"
658
+ ):
657
659
df .query ("a == @c" , engine = engine , parser = parser )
658
660
659
661
def test_index_resolvers_come_after_columns_with_the_same_name (self ):
@@ -784,7 +786,7 @@ def test_nested_scope(self):
784
786
with pytest .raises (SyntaxError ):
785
787
df .query ("(@df>0) & (@df2>0)" , engine = engine , parser = parser )
786
788
787
- with pytest .raises (UndefinedVariableError ):
789
+ with pytest .raises (UndefinedVariableError , match = "name 'df' is not defined" ):
788
790
df .query ("(df>0) & (df2>0)" , engine = engine , parser = parser )
789
791
790
792
expected = df [(df > 0 ) & (df2 > 0 )]
0 commit comments