Skip to content

ValueError from operations between Series with specific names  #39757

Closed
@dan1261

Description

@dan1261

The following raises a ValueError due to comparison of the two names in the function _maybe_match_name (core/ops/common.py).

>>> from pandas import Series
>>> import numpy as np
>>> series_a = Series([1,2,3], name=np.float64(1.0))
>>> series_b = Series([1,2,3], name=(np.float64(1.0), np.float64(2.0)))
>>> series_a + series_b

It seems to only occur when comparison a tuple of numpy dtypes to a single numpy dtype, but I didn't test every possible combination. It does not occur when using built-in floats, I imagine this is due to overloading of the == operator by the numpy dtypes when the other operand is a tuple.

There is a nearby TODO "what if they both have np.nan for their names?" I don't know how feasible it is to consider every case where equality fails, but it seems a try/except returning None would seem to resolve this issue, and be in line with the default return value if the names do not compare equal. I would be keen to implement this simple fix if it seems sensible.

INSTALLED VERSIONS

commit : None
python : 3.8.0.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 9, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United Kingdom.1252
pandas : 1.0.3
numpy : 1.19.0
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.4
setuptools : 47.3.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.5.0
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.19.0
pandas_datareader: 0.8.1
bs4 : 4.9.1
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.5.0
matplotlib : 3.2.2
numexpr : 2.7.1
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : 1.5.0
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : 0.51.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNumeric OperationsArithmetic, Comparison, and Logical operationsSeriesSeries data structure

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions