Skip to content

Commit ab1ce4e

Browse files
Alexander LakeevAlex-Blade
Alexander Lakeev
authored andcommitted
TST: Add tests for empty dicts in eval scopes
1 parent 0e0b555 commit ab1ce4e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pandas/tests/computation/test_eval.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from pandas.core.computation.ops import (
4545
ARITH_OPS_SYMS,
4646
SPECIAL_CASE_ARITH_OPS_SYMS,
47+
UndefinedVariableError,
4748
_binary_math_ops,
4849
_binary_ops_dict,
4950
_unary_math_ops,
@@ -1659,6 +1660,18 @@ def test_no_new_globals(self, engine, parser):
16591660
gbls2 = globals().copy()
16601661
assert gbls == gbls2
16611662

1663+
def test_empty_locals(self, engine, parser):
1664+
x = 1
1665+
msg = "name 'x' is not defined"
1666+
with pytest.raises(UndefinedVariableError, match=msg):
1667+
pd.eval("x + 1", engine=engine, parser=parser, local_dict={})
1668+
1669+
def test_empty_globals(self, engine, parser):
1670+
msg = "name '_var_s' is not defined"
1671+
e = "_var_s * 2"
1672+
with pytest.raises(UndefinedVariableError, match=msg):
1673+
pd.eval(e, engine=engine, parser=parser, global_dict={})
1674+
16621675

16631676
@td.skip_if_no_ne
16641677
def test_invalid_engine():

0 commit comments

Comments
 (0)