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

BUG: Inconsistent name of binary operations between Series and ndarray, list, tuple #33930

Closed
3 tasks done
gshimansky opened this issue May 1, 2020 · 0 comments · Fixed by #36760
Closed
3 tasks done
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations
Milestone

Comments

@gshimansky
Copy link

gshimansky commented May 1, 2020

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

import numpy as np
import pandas as pd

s1 = pd.Series([1, 2, 3, 4, 5], name = "s1")
nparray = np.arange(1, len(s1) + 1)
s2 = s1 / nparray
print("s2.name = ", s2.name)
s3 = s1.div(nparray)
print("s3.name = ", s3.name)

numbers_list = [1.0, 2.0, 3.0, 4.0, 5.0]
s4 = s1 / numbers_list
print("s4.name = ", s4.name)
s5 = s1.div(numbers_list)
print("s5.name = ", s5.name)

numbers_tuple = (1.0, 2.0, 3.0, 4.0, 5.0)
s6 = s1 / numbers_tuple
print("s6.name = ", s6.name)
s7 = s1.div(numbers_tuple)
print("s7.name = ", s7.name)

Problem description

[this should explain why the current behaviour is a problem and why the expected output is a better solution]

Depending on how binary operation is done, e.g. arithmetic operation or function call resulting name is different.

  • In case of function call it is preserved because Series object with no name is constructed from ndarray, list or tuple https://github.com/pandas-dev/pandas/blob/master/pandas/core/ops/__init__.py#L476. Call for get_op_result_name with arguments of original Series object and constructed Series object with no name leads to name being set to None.
  • In case of arithmetic operation no Series object is created in _arith_method_SERIES and call to get_op_result_name to arguments of Series and non-ABCSeries, non-ABCIndexClass leads to name of Series operand being preserved.

Expected Output

Output of pd.show_versions()

[paste the output of pd.show_versions() here leaving a blank line after the details tag]

INSTALLED VERSIONS

commit : None
python : 3.7.7.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 12, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : None.None

pandas : 1.0.3
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 20.1
setuptools : 41.2.0
Cython : 0.29.17
pytest : 5.3.5
hypothesis : None
sphinx : None
blosc : None
feather : 0.4.0
xlsxwriter : None
lxml.etree : 4.5.0
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.1
IPython : 7.13.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.5.0
matplotlib : 3.2.0
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.3
pandas_gbq : 0.13.1
pyarrow : 0.16.0
pytables : None
pytest : 5.3.5
pyxlsb : None
s3fs : 0.4.0
scipy : 1.4.1
sqlalchemy : 1.3.15
tables : None
tabulate : None
xarray : 0.15.0
xlrd : 1.2.0
xlwt : None
xlsxwriter : None
numba : None

INSTALLED VERSIONS

commit : 81093ba
python : 3.7.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.3.0-26-generic
Version : #28-Ubuntu SMP Wed Dec 18 05:37:46 UTC 2019
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.1.0.dev0+1453.g81093ba82
numpy : 1.17.3
pytz : 2019.2
dateutil : 2.7.3
pip : 18.1
setuptools : 41.1.0
Cython : 0.29.17
pytest : 5.3.5
hypothesis : None
sphinx : None
blosc : None
feather : 0.4.0
xlsxwriter : None
lxml.etree : 4.5.0
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.1
IPython : 7.12.0
pandas_datareader: None
bs4 : 4.8.2
bottleneck : None
fastparquet : None
gcsfs : None
matplotlib : 3.1.3
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.3
pandas_gbq : None
pyarrow : 0.13.0
pytables : None
pyxlsb : None
s3fs : 0.4.2
scipy : 1.4.1
sqlalchemy : 1.3.11
tables : 3.6.1
tabulate : None
xarray : 0.15.1
xlrd : 1.2.0
xlwt : None
numba : 0.46.0

@gshimansky gshimansky added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels May 1, 2020
@jbrockmendel jbrockmendel added Numeric Operations Arithmetic, Comparison, and Logical operations and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 5, 2020
@jreback jreback added this to the 1.2 milestone Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants