pydata / numexpr

Fast numerical array expression evaluator for Python, NumPy, Pandas, PyTables and more
https://numexpr.readthedocs.io/en/latest/user_guide.html
MIT License
2.25k stars 212 forks source link

Python 3.13.0b1: test suite (69 failures) AttributeError: 'FrameLocalsProxy' object has no attribute 'clear' #488

Closed befeleme closed 6 months ago

befeleme commented 6 months ago

When mitigating 'unittest.makeSuite()` issue, the test suite runs, but multiple errors with the same traceback happen.

ERROR: test_multithread (numexpr.tests.test_numexpr.test_threading.test_multithread)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/python-numexpr-2.8.5-build/numexpr-2.8.5/build/lib.linux-x86_64-cpython-313/numexpr/tests/test_numexpr.py", line 1072, in test_multithread
    work(10)  # warm compilation cache
    ~~~~^^^^
  File "/builddir/build/BUILD/python-numexpr-2.8.5-build/numexpr-2.8.5/build/lib.linux-x86_64-cpython-313/numexpr/tests/test_numexpr.py", line 1070, in work
    evaluate('a+a')
    ~~~~~~~~^^^^^^^
  File "/builddir/build/BUILD/python-numexpr-2.8.5-build/numexpr-2.8.5/build/lib.linux-x86_64-cpython-313/numexpr/necompiler.py", line 818, in evaluate
    arguments = getArguments(names, local_dict, global_dict)
  File "/builddir/build/BUILD/python-numexpr-2.8.5-build/numexpr-2.8.5/build/lib.linux-x86_64-cpython-313/numexpr/necompiler.py", line 751, in getArguments
    local_dict.clear()
    ^^^^^^^^^^^^^^^^
AttributeError: 'FrameLocalsProxy' object has no attribute 'clear'

----------------------------------------------------------------------
Ran 5530 tests in 1.506s

FAILED (errors=69)
hroncok commented 6 months ago
diff --git a/numexpr/necompiler.py b/numexpr/necompiler.py
index 9291d44..a3cd39b 100644
--- a/numexpr/necompiler.py
+++ b/numexpr/necompiler.py
@@ -747,7 +747,7 @@ def getArguments(names, local_dict=None, global_dict=None):
         # If we generated local_dict via an explicit reference to f_locals,
         # clear the dict to prevent creating extra ref counts in the caller's scope
         # See https://github.com/pydata/numexpr/issues/310
-        if clear_local_dict:
+        if clear_local_dict and hasattr(local_dict, 'clear'):
             local_dict.clear()

     return arguments

This makes the tests pass.