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

0.25.1 pandas.core.frame.DataFrame.eval() erroring-out on Python 3.7 (but not on Python 3.6) #29819

Closed
JohnMount opened this issue Nov 23, 2019 · 1 comment
Labels
Bug expressions pd.eval, query

Comments

@JohnMount
Copy link

JohnMount commented Nov 23, 2019

Code Sample

import sys
import pandas
import numpy

print("# sys.version: " + sys.version)
print("# pandas.__version__: " + pandas.__version__)
print("# numpy.__version__: " + numpy.__version__)

d = pandas.DataFrame({
    "a": [True, False],
    "b": [1, 2],
    "c": [3, 4]})


pandas_eval_env = {
            "if_else": lambda c, x, y: numpy.where(c, x, y),
        }

d.eval("@if_else(a, 1, c)", local_dict=pandas_eval_env, global_dict=None)

Problem description

For Python 3.6 the above code runs. For Python 3.7 it errors-out with "TypeError: unhashable type: 'numpy.ndarray'". If I am returning the wrong type (an array instead of a named series or dataframe) I apologize.

Expected Output

For Python 3.6 we get what I expected:

array([1, 4])

For Python 3.7 0.25.1 pandas we get the following:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/johnmount/opt/anaconda3/lib/python3.7/site-packages/pandas/core/frame.py", line 3300, in eval
    return _eval(expr, inplace=inplace, **kwargs)
  File "/Users/johnmount/opt/anaconda3/lib/python3.7/site-packages/pandas/core/computation/eval.py", line 327, in eval
    ret = eng_inst.evaluate()
  File "/Users/johnmount/opt/anaconda3/lib/python3.7/site-packages/pandas/core/computation/engines.py", line 70, in evaluate
    res = self._evaluate()
  File "/Users/johnmount/opt/anaconda3/lib/python3.7/site-packages/pandas/core/computation/engines.py", line 118, in _evaluate
    _check_ne_builtin_clash(self.expr)
  File "/Users/johnmount/opt/anaconda3/lib/python3.7/site-packages/pandas/core/computation/engines.py", line 27, in _check_ne_builtin_clash
    names = expr.names
  File "/Users/johnmount/opt/anaconda3/lib/python3.7/site-packages/pandas/core/computation/expr.py", line 850, in names
    return frozenset([self.terms.name])
TypeError: unhashable type: 'numpy.ndarray'

Note: both failing and successful runs are using Pandas 0.25.1 and numpy 1.17.2.

Edit: Pandas 0.25.3 with Python 3.7.5, numpy 1.17.3 works fine. My question then is: is there a work around for when we are using Pandas 0.25.1?

Output of pd.show_versions()

Working version:

sys.version: 3.6.9 |Anaconda, Inc.| (default, Jul 30 2019, 13:42:17) 
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]
pandas.__version__:0.25.1
numpy.__version__: 1.17.2
Out[4]: array([1, 4])
pandas.show_versions()
INSTALLED VERSIONS
------------------
commit           : None
python           : 3.6.9.final.0
python-bits      : 64
OS               : Darwin
OS-release       : 17.7.0
machine          : x86_64
processor        : i386
byteorder        : little
LC_ALL           : None
LANG             : None
LOCALE           : en_US.UTF-8
pandas           : 0.25.1
numpy            : 1.17.2
pytz             : 2019.3
dateutil         : 2.8.0
pip              : 19.3.1
setuptools       : 41.6.0.post20191030
Cython           : None
pytest           : 5.2.2
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : 2.10.3
IPython          : 7.9.0
pandas_datareader: None
bs4              : None
bottleneck       : None
fastparquet      : None
gcsfs            : None
lxml.etree       : None
matplotlib       : 3.1.1
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pytables         : None
s3fs             : None
scipy            : 1.3.1
sqlalchemy       : None
tables           : None
xarray           : None
xlrd             : 1.2.0
xlwt             : None
xlsxwriter       : None

Failing version:

INSTALLED VERSIONS
------------------
commit           : None
python           : 3.7.4.final.0
python-bits      : 64
OS               : Darwin
OS-release       : 17.7.0
machine          : x86_64
processor        : i386
byteorder        : little
LC_ALL           : None
LANG             : en_US.UTF-8
LOCALE           : en_US.UTF-8

pandas           : 0.25.1
numpy            : 1.17.2
pytz             : 2019.3
dateutil         : 2.8.0
pip              : 19.2.3
setuptools       : 41.4.0
Cython           : 0.29.13
pytest           : 5.2.1
hypothesis       : None
sphinx           : 2.2.0
blosc            : None
feather          : None
xlsxwriter       : 1.2.1
lxml.etree       : 4.4.1
html5lib         : 1.0.1
pymysql          : None
psycopg2         : None
jinja2           : 2.10.3
IPython          : 7.8.0
pandas_datareader: None
bs4              : 4.8.0
bottleneck       : 1.2.1
fastparquet      : None
gcsfs            : None
lxml.etree       : 4.4.1
matplotlib       : 3.1.1
numexpr          : 2.7.0
odfpy            : None
openpyxl         : 3.0.0
pandas_gbq       : None
pyarrow          : None
pytables         : None
s3fs             : None
scipy            : 1.3.1
sqlalchemy       : 1.3.9
tables           : 3.5.2
xarray           : None
xlrd             : 1.2.0
xlwt             : 1.3.0
xlsxwriter       : 1.2.1
@JohnMount JohnMount changed the title pandas.DatatFrame.eval() erroring-out on Python 3.7 (but not Python 3.6) pandas.core.frame.DataFrame.eval() erroring-out on Python 3.7 (but not Python 3.6) Nov 23, 2019
@JohnMount JohnMount changed the title pandas.core.frame.DataFrame.eval() erroring-out on Python 3.7 (but not Python 3.6) pandas.core.frame.DataFrame.eval() erroring-out on Python 3.7 (but not on Python 3.6) Nov 23, 2019
@JohnMount JohnMount changed the title pandas.core.frame.DataFrame.eval() erroring-out on Python 3.7 (but not on Python 3.6) 0.25.1 pandas.core.frame.DataFrame.eval() erroring-out on Python 3.7 (but not on Python 3.6) Nov 23, 2019
@jbrockmendel jbrockmendel added the expressions pd.eval, query label Nov 30, 2019
@mroeschke mroeschke added the Bug label Apr 26, 2020
@mroeschke
Copy link
Member

This looks to work on main and looks like a dependency issue. Since we require newer version of these libraries, closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug expressions pd.eval, query
Projects
None yet
Development

No branches or pull requests

3 participants