Skip to content

Commit 16bc7de

Browse files
unmatched backtick or quote can raise SyntaxError OR TokenError
1 parent 9d8a4c5 commit 16bc7de

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pandas/tests/frame/test_query_eval.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import operator
2+
from tokenize import TokenError
23

34
import numpy as np
45
import pytest
@@ -1446,7 +1447,7 @@ def test_expr_with_no_backticks(self):
14461447
def test_expr_with_no_quotes_and_backtick_is_unmatched(self):
14471448
# GH 59285
14481449
df = DataFrame((1, 5, 10), columns=["column-name"])
1449-
with pytest.raises(SyntaxError, match="invalid syntax"):
1450+
with pytest.raises((SyntaxError, TokenError), match="invalid syntax"):
14501451
df.query("5 < `column-name")
14511452

14521453
def test_expr_with_no_quotes_and_backtick_is_matched(self):
@@ -1459,7 +1460,9 @@ def test_expr_with_no_quotes_and_backtick_is_matched(self):
14591460
def test_expr_with_backtick_opened_before_quote_and_backtick_is_unmatched(self):
14601461
# GH 59285
14611462
df = DataFrame((1, 5, 10), columns=["It's"])
1462-
with pytest.raises(SyntaxError, match="unterminated string literal"):
1463+
with pytest.raises(
1464+
(SyntaxError, TokenError), match="unterminated string literal"
1465+
):
14631466
df.query("5 < `It's")
14641467

14651468
def test_expr_with_backtick_opened_before_quote_and_backtick_is_matched(self):
@@ -1472,7 +1475,9 @@ def test_expr_with_backtick_opened_before_quote_and_backtick_is_matched(self):
14721475
def test_expr_with_quote_opened_before_backtick_and_quote_is_unmatched(self):
14731476
# GH 59285
14741477
df = DataFrame(("aaa", "vvv", "zzz"), columns=["column-name"])
1475-
with pytest.raises(SyntaxError, match="unterminated string literal"):
1478+
with pytest.raises(
1479+
(SyntaxError, TokenError), match="unterminated string literal"
1480+
):
14761481
df.query("`column-name` < 'It`s that\\'s \"quote\" #hash")
14771482

14781483
def test_expr_with_quote_opened_before_backtick_and_quote_is_matched_at_end(self):

0 commit comments

Comments
 (0)