Skip to content

TST: add some message checks in test_query_eval #29994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions pandas/tests/frame/test_query_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,13 @@ def test_query_scope(self):
tm.assert_frame_equal(res, expected)

# no local variable c
with pytest.raises(UndefinedVariableError):
with pytest.raises(
UndefinedVariableError, match="local variable 'c' is not defined"
):
df.query("@a > b > @c", engine=engine, parser=parser)

# no column named 'c'
with pytest.raises(UndefinedVariableError):
with pytest.raises(UndefinedVariableError, match="name 'c' is not defined"):
df.query("@a > b > c", engine=engine, parser=parser)

def test_query_doesnt_pickup_local(self):
Expand All @@ -494,7 +496,7 @@ def test_query_doesnt_pickup_local(self):
df = DataFrame(np.random.randint(m, size=(n, 3)), columns=list("abc"))

# we don't pick up the local 'sin'
with pytest.raises(UndefinedVariableError):
with pytest.raises(UndefinedVariableError, match="name 'sin' is not defined"):
df.query("sin > 5", engine=engine, parser=parser)

def test_query_builtin(self):
Expand Down Expand Up @@ -588,7 +590,7 @@ def test_nested_raises_on_local_self_reference(self):
df = DataFrame(np.random.randn(5, 3))

# can't reference ourself b/c we're a local so @ is necessary
with pytest.raises(UndefinedVariableError):
with pytest.raises(UndefinedVariableError, match="name 'df' is not defined"):
df.query("df > 0", engine=self.engine, parser=self.parser)

def test_local_syntax(self):
Expand Down Expand Up @@ -651,9 +653,9 @@ def test_query_undefined_local(self):
skip_if_no_pandas_parser(parser)

df = DataFrame(np.random.rand(10, 2), columns=list("ab"))
msg = "local variable 'c' is not defined"

with pytest.raises(UndefinedVariableError, match=msg):
with pytest.raises(
UndefinedVariableError, match="local variable 'c' is not defined"
):
df.query("a == @c", engine=engine, parser=parser)

def test_index_resolvers_come_after_columns_with_the_same_name(self):
Expand Down Expand Up @@ -784,7 +786,7 @@ def test_nested_scope(self):
with pytest.raises(SyntaxError):
df.query("(@df>0) & (@df2>0)", engine=engine, parser=parser)

with pytest.raises(UndefinedVariableError):
with pytest.raises(UndefinedVariableError, match="name 'df' is not defined"):
df.query("(df>0) & (df2>0)", engine=engine, parser=parser)

expected = df[(df > 0) & (df2 > 0)]
Expand Down