CODAIT / text-extensions-for-pandas

Natural language processing support for Pandas dataframes.
Apache License 2.0
215 stars 34 forks source link

AttributeError: module 'pandas.core.ops' #248

Closed mboldin closed 1 year ago

mboldin commented 1 year ago

I am running on Windows 10 Intel i5 and get import error with

import pandas as pd import text_extensions_for_pandas as tp when run in Jupyter Notebook

the relevant error code is AttributeError: module 'pandas.core.ops' has no attribute '_get_op_name'

imports worked 6 weeks ago fail now and I have no problem with import text_extensions_for_pandas not in Jupyter I tried to create a virtenv just for this problem and installed full pip install of pandas, text_extensions_for_pandas and jupyter and I see the same error only in Jupyter see ERROR in context for more detail

Versions pandas 1.3.5

and Selected Jupyter core packages... IPython : 7.34.0 ipykernel : 6.15.2 ipywidgets : 8.0.2 jupyter_client : 7.3.5 jupyter_core : 4.11.1 jupyter_server : not installed jupyterlab : not installed nbclient : 0.6.7 nbconvert : 7.0.0 nbformat : 5.4.0 notebook : 6.4.12 qtconsole : 5.3.2 traitlets : 5.3.0

I am not 100% sure of the text_extensions_for_pandas versions maybe 0.2.0

(text_pandas) C:\Users\mdbol\Desktop\virtenv\text_pandas>pip install text_extensions_for_pandas Collecting text_extensions_for_pandas Using cached text_extensions_for_pandas-0.2.0-py3-none-any.whl (199 kB)


ERROR In context: ~\AppData\Local\Programs\Python\Python37\lib\site-packages\text_extensions_for_pandas\array__init__.py in 25 from text_extensions_for_pandas.array.char_span import 26 from text_extensions_for_pandas.array.token_span import ---> 27 from text_extensions_for_pandas.array.tensor import 28 from text_extensions_for_pandas.array.accessor import 29

~\AppData\Local\Programs\Python\Python37\lib\site-packages\text_extensions_for_pandas\array\tensor.py in 281 282 # Add operators from the mixin to the class --> 283 TensorArray._add_arithmetic_ops() 284 TensorArray._add_comparison_ops()

~\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\arrays\base.py in _add_arithmetic_ops(cls) 1342 @classmethod 1343 def _add_arithmetic_ops(cls): -> 1344 setattr(cls, "add", cls._create_arithmetic_method(operator.add)) 1345 setattr(cls, "radd", cls._create_arithmetic_method(ops.radd)) 1346 setattr(cls, "sub", cls._create_arithmetic_method(operator.sub))

~\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\arrays\base.py in _create_arithmetic_method(cls, op) 1495 @classmethod 1496 def _create_arithmetic_method(cls, op): -> 1497 return cls._create_method(op) 1498 1499 @classmethod

~\AppData\Local\Programs\Python\Python37\lib\site-packages\text_extensions_for_pandas\array\tensor.py in _create_method(cls, op, coerce_to_dtype) 92 return TensorArray(res) 93 ---> 94 op_name = ops._get_op_name(op, True) 95 return set_function_name(_binop, op_name, cls) 96

AttributeError: module 'pandas.core.ops' has no attribute '_get_op_name'

mboldin commented 1 year ago

UPDATE:

Looking at the Jupyter consoile output, I see:

[IPKernelApp] ERROR | No such comm target registered: jupyter.widget.control [IPKernelApp] WARNING | No such comm: 86364858-6645-43b9-8ee3-3f3405095abe

when import text_extensions_for_pandas fails

A Google search of this error string shows it has been reported for other packages (not text_extensions_for_pandas) as a result of problems related to ipywidgets see https://github.com/jupyter-widgets/ipywidgets/issues/2257

So I doubt it is a fixable TEXT_EXTENSIONS_FOR_PANDAS I will close this issue in a few days if this diagnosis is right, and in meantime hope someone report here a workaround.

mboldin commented 1 year ago

FIXED -- for me My jupyter run was pointing to an old pre-alpha version of text_extensions_for_pandas I deleted this, and forced a new install of he module and all is OK The bad line ---> 94 op_name = ops._get_op_name(op, True) was from an old version of tensor.py the latest 0.2.0 version has different code logic for def _create_method(cls, op, coerce_to_dtype=True, result_dtype=None):

frreiss commented 1 year ago

Glad this issue is resolved for you now. Let us know if you have any other problems.