Skip to content

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

Closed
@gshimansky

Description

@gshimansky
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNumeric OperationsArithmetic, Comparison, and Logical operations

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions