-
[x] I have checked that this issue has not already been reported.
-
[x] 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()
Comment From: phofl
Hi, thanks for your report. When executing this on master, I get the expected output. Seems to be fixed
Comment From: rhshadrach
@phofl: On master I get:
ValueError: cannot reindex from a duplicate axis
Comment From: phofl
Hm, seems that I was on a feature branch locally, which did not raise the error. I will try to find out which one...
Comment From: phofl
Hm weird, can not replicate this...
Comment From: rhshadrach
@phofl: By "this" do you mean you can't replicate the ValueError or can't replicate the feature branch fix?
Comment From: phofl
Unfortunately I can not replicate the fix :( Tested all branches...
Comment From: jbrockmendel
This works correctly on main, but the user is incorrectly expecting this to behave like df.sub(df.a, axis=0)
instead of df.sub(df.a, axis=1)
.