Open
Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
# pip install 'numpy>=2.0.0rc1' 'pandas==2.2.2' hypothesis pytest numexpr
import pandas
pandas.test(extra_args=["-k", "test_eval and numexpr", "-l", "--tb=long"])
Issue Description
I'm currently testing numpy 2 on the the openSUSE python ecosystem. I notice the pandas test suite failing when numpy 2.0.0rc1 is installed instead of 1.26.4.
See also pydata/numexpr#483
============================================================================================= FAILURES =============================================================================================
___________________________________________________________ TestTypeCasting.test_binop_typecasting[numexpr-python-left_right0-float64-/] ___________________________________________________________
self = <pandas.tests.computation.test_eval.TestTypeCasting object at 0x7fdda001f250>, engine = 'numexpr', parser = 'python', op = '/', dt = <class 'numpy.float64'>, left_right = ('df', '3')
@pytest.mark.parametrize("op", ["+", "-", "*", "**", "/"])
# maybe someday... numexpr has too many upcasting rules now
# chain(*(np.core.sctypes[x] for x in ['uint', 'int', 'float']))
@pytest.mark.parametrize("dt", [np.float32, np.float64])
@pytest.mark.parametrize("left_right", [("df", "3"), ("3", "df")])
def test_binop_typecasting(self, engine, parser, op, dt, left_right):
df = DataFrame(np.random.default_rng(2).standard_normal((5, 3)), dtype=dt)
left, right = left_right
s = f"{left} {op} {right}"
> res = pd.eval(s, engine=engine, parser=parser)
df = 0 1 2
0 0.189053 -0.522748 -0.413064
1 -2.441467 1.799707 1.144166
2 -0.325423 0.773807 0.281211
3 -0.553823 0.977567 -0.310557
4 -0.328824 -0.792147 0.454958
dt = <class 'numpy.float64'>
engine = 'numexpr'
left = 'df'
left_right = ('df', '3')
op = '/'
parser = 'python'
right = '3'
s = 'df / 3'
self = <pandas.tests.computation.test_eval.TestTypeCasting object at 0x7fdda001f250>
pdtestenv/lib64/python3.11/site-packages/pandas/tests/computation/test_eval.py:756:
...
> ret = eng_inst.evaluate()
eng = <class 'pandas.core.computation.engines.NumExprEngine'>
eng_inst = <pandas.core.computation.engines.NumExprEngine object at 0x7fdd41459490>
engine = 'numexpr'
env = Scope(scope=['Timestamp',
'datetime',
'True',
'False',
'list',
'tuple',
'inf',
'Inf',
'__name__',
'__doc__',
...t_set_inplace',
'TestValidate',
'self',
'op',
'dt',
'left_right',
'df',
'left',
'right',
's']
, resolvers=[]
)
expr = 'df / 3'
exprs = ['df / 3']
first_expr = True
global_dict = None
inplace = False
level = 0
local_dict = None
multi_line = False
parsed_expr = (df) / (np.float64(3.0))
parser = 'python'
resolvers = ()
ret = None
target = None
target_modified = False
pdtestenv/lib64/python3.11/site-packages/pandas/core/computation/eval.py:357:
...
==================================================================================== short test summary info ======================================================================================
FAILED pdtestenv/lib64/python3.11/site-packages/pandas/tests/computation/test_eval.py::TestTypeCasting::test_binop_typecasting[numexpr-python-left_right0-float64-/] - ValueError: Expression (df) / (np.float64(3.0)) has forbidden control characters.
FAILED pdtestenv/lib64/python3.11/site-packages/pandas/tests/computation/test_eval.py::TestTypeCasting::test_binop_typecasting[numexpr-python-left_right1-float64-/] - ValueError: Expression (np.float64(3.0)) / (df) has forbidden control characters.
FAILED pdtestenv/lib64/python3.11/site-packages/pandas/tests/computation/test_eval.py::TestTypeCasting::test_binop_typecasting[numexpr-pandas-left_right0-float64-/] - ValueError: Expression (df) / (np.float64(3.0)) has forbidden control characters.
FAILED pdtestenv/lib64/python3.11/site-packages/pandas/tests/computation/test_eval.py::TestTypeCasting::test_binop_typecasting[numexpr-pandas-left_right1-float64-/] - ValueError: Expression (np.float64(3.0)) / (df) has forbidden control characters.
FAILED pdtestenv/lib64/python3.11/site-packages/pandas/tests/computation/test_eval.py::TestOperations::test_simple_arith_ops[numexpr-python] - ValueError: Expression (np.float64(1.0)) / (np.float64(1.0)) has forbidden control characters.
FAILED pdtestenv/lib64/python3.11/site-packages/pandas/tests/computation/test_eval.py::TestOperations::test_simple_arith_ops[numexpr-pandas] - ValueError: Expression (np.float64(1.0)) / (np.float64(1.0)) has forbidden control characters.
====================================================== 6 failed, 5432 passed, 62 skipped, 199038 deselected, 2 xpassed, 4 warnings in 32.69s =======================================================
Expected Behavior
Passing test suite, proper string evaluation
Installed Versions
INSTALLED VERSIONS
------------------
commit : d9cdd2ee5a58015ef6f4d15c7226110c9aab8140
python : 3.11.9.final.0
python-bits : 64
OS : Linux
OS-release : 6.8.7-1-default
Version : #1 SMP PREEMPT_DYNAMIC Thu Apr 18 07:12:38 UTC 2024 (5c0cf23)
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : de_DE.UTF-8
LOCALE : de_DE.UTF-8
pandas : 2.2.2
numpy : 2.0.0rc1
pytz : 2024.1
dateutil : 2.9.0.post0
setuptools : 65.5.0
pip : 24.0
Cython : None
pytest : 8.2.0
hypothesis : 6.100.2
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : 2.10.0
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None