Skip to content
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

Fix evaluations on Python 3.12 #57391

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
)
from pandas._libs.lib import is_string_array
from pandas._libs.tslibs import timezones
from pandas.compat import PY312
from pandas.compat._optional import import_optional_dependency
from pandas.compat.pickle_compat import patch_pickle
from pandas.errors import (
Expand Down Expand Up @@ -170,8 +171,12 @@ def _ensure_term(where, scope_level: int):
# list
level = scope_level + 1
if isinstance(where, (list, tuple)):
# Python 3.12 does not a scope for list comprehensions, but older versions did:
# https://docs.python.org/3.12/whatsnew/3.12.html#whatsnew312-pep709
if not PY312:
level += 1
where = [
Term(term, scope_level=level + 1) if maybe_expression(term) else term
Term(term, scope_level=level) if maybe_expression(term) else term
for term in where
if term is not None
]
Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/computation/test_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,7 @@ def test_series_pos(self, lhs, engine, parser):

def test_scalar_unary(self, engine, parser):
msg = "bad operand type for unary ~: 'float'"
warn = None
if PY312 and not (engine == "numexpr" and parser == "pandas"):
warn = DeprecationWarning
warn = DeprecationWarning if PY312 else None
with pytest.raises(TypeError, match=msg):
pd.eval("~1.0", engine=engine, parser=parser)

Expand Down
Loading