Skip to content

BUG: Incorrect behavior of binary operations when left/right operands have different type (Series/DataFrame) #37663

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

Open
2 of 3 tasks
prutskov opened this issue Nov 6, 2020 · 6 comments
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations

Comments

@prutskov
Copy link

prutskov commented Nov 6, 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 pandas as pd

df = pd.DataFrame([0,1,2]).append(pd.DataFrame([3,4,5]))
df.columns = ['a']
print(df - df.a)

Problem description

Why we can not to do binary operations when we work with DataFrame and Series(dataframe has 1 columns, len(df.index)==len(series.index)) with duplicated indexes? If left and right operands have the same type (DataFrame/DataFrame` for example) it works.

Expected Output

0    0
1    0
2    0
0    0
1    0
2    0

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 67a3d42
python : 3.8.3.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-50-generic
Version : #54-Ubuntu SMP Mon May 6 18:46:08 UTC 2019
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US
LOCALE : en_US.ISO8859-1

pandas : 1.1.4
numpy : 1.19.2
pytz : 2020.1
dateutil : 2.8.1
pip : 20.0.2
setuptools : 46.4.0.post20200518
Cython : None
pytest : 6.1.1
hypothesis : None
sphinx : None
blosc : None
feather : 0.4.1
xlsxwriter : None
lxml.etree : 4.5.2
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : None
pandas_datareader: None
bs4 : 4.9.3
bottleneck : None
fsspec : 0.8.3
fastparquet : None
gcsfs : None
matplotlib : 3.2.2
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.5
pandas_gbq : 0.14.0
pyarrow : 1.0.0
pytables : None
pyxlsb : None
s3fs : 0.5.1
scipy : 1.5.2
sqlalchemy : 1.3.19
tables : 3.6.1
tabulate : None
xarray : 0.16.1
xlrd : 1.2.0
xlwt : None
numba : None

@prutskov prutskov added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 6, 2020
@prutskov prutskov changed the title BUG: BUG: Incorrect behavior of binary operations when left/right operands have different type (Series/DataFrame) Nov 6, 2020
@phofl
Copy link
Member

phofl commented Nov 6, 2020

Hi, thanks for your report. When executing this on master, I get the expected output. Seems to be fixed

@rhshadrach
Copy link
Member

@phofl: On master I get:

ValueError: cannot reindex from a duplicate axis

@phofl
Copy link
Member

phofl commented Nov 6, 2020

Hm, seems that I was on a feature branch locally, which did not raise the error. I will try to find out which one...

@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 Nov 6, 2020
@phofl
Copy link
Member

phofl commented Nov 6, 2020

Hm weird, can not replicate this...

@rhshadrach
Copy link
Member

@phofl: By "this" do you mean you can't replicate the ValueError or can't replicate the feature branch fix?

@phofl
Copy link
Member

phofl commented Nov 7, 2020

Unfortunately I can not replicate the fix :(
Tested all branches...

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

No branches or pull requests

4 participants