Skip to content

Undocumented behavior change (1.0.5->1.1.0) when using arithmetic operations on dataframes #36702

Closed
@mhaselsteiner

Description

@mhaselsteiner
  • 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.


Code Sample, a copy-pastable example

pandas 1.0.5:

(pd.DataFrame({'x':[1,2,],'y':[1,2]})+[pd.Series([1,1]),pd.Series([1,1]) ]).iloc[0,0]
Out[37]: 2

pandas 1.1.0:

>>> (pd.DataFrame({'x':[1,2,],'y':[1,2]})+[pd.Series([1,1]),pd.Series([1,1]) ]).iloc[0,0]
0    2
1    2
dtype: int64

Problem description

When applying arithmetic operations between dataframe and list of Series prior to 1.0.5 and we get different results then starting with 1.1.0. Starting with 1.1.0 we seem to get a another level of indexing, altough the dataframes columns and index return the same values, iterating over it returns different objects.

Since now the return type of the chained iloc has changed from float/int to series, this breaks functions using the arithmetic operator like this.

Expected Output

Output of pd.show_versions()

using the latest pandas version:

INSTALLED VERSIONS ------------------ commit : 2a7d332 python : 3.8.5.final.0 python-bits : 64 OS : Linux OS-release : 5.4.0-48-generic Version : #52-Ubuntu SMP Thu Sep 10 10:58:49 UTC 2020 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8

pandas : 1.1.2
numpy : 1.19.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.3
setuptools : 49.6.0.post20200917
Cython : None
pytest : 6.0.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.18.1
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.2
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

using 1.0.3

INSTALLED VERSIONS ------------------ commit : None python : 3.8.3.final.0 python-bits : 64 OS : Linux OS-release : 5.4.0-48-generic machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8 pandas : 1.0.3 numpy : 1.18.5 pytz : 2020.1 dateutil : 2.8.1 pip : 20.1.1 setuptools : 47.3.1.post20200616 Cython : None pytest : 5.4.3 hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : 1.0.1 pymysql : None psycopg2 : None jinja2 : 2.11.2 IPython : 7.15.0 pandas_datareader: None bs4 : None bottleneck : None fastparquet : None gcsfs : None lxml.etree : None matplotlib : 3.2.1 numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pytables : None pytest : 5.4.3 pyxlsb : None s3fs : None scipy : 1.4.1 sqlalchemy : 1.3.18 tables : None tabulate : None xarray : None xlrd : None xlwt : None xlsxwriter : None numba : NoneI

Metadata

Metadata

Assignees

Labels

Error ReportingIncorrect or improved errors from pandasNumeric OperationsArithmetic, Comparison, and Logical operations

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions