You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the master branch of pandas.
Reproducible Example
importpandasaspddf=pd.DataFrame({"A": [1, 2], "B": [2, 0], "C": [4, 2]}, index=["AA", "BB"])
# Add half of column C to the other two columnsdf[["A", "B"]] +df["C"] /2
Issue Description
I'm marked this as a bug because I am under the impression that this worked as I expected in a previous version, but I can't be sure.
I had assumed that this operator would intelligently align the series with the columns of the data frame, since the index of the series is the same object as the index of the dataframe, rather than defaulting to axis="columns" as for the add method.
Above gives
A
AA
B
BB
AA
NaN
NaN
NaN
NaN
BB
NaN
NaN
NaN
NaN
It feels like the operator versions of the binary operations could have the additional logic to attempt to intelligently choose which axis to use to broadcast when operating on a dataframe and a series. If you need to specific the axis for speed or because it's possible to make the wrong choice, then I think it's OK to expect people to use the method version.
However, if this is the intended behaviour, then it's probably worth adding something in the docs. In fact, I can't find any documentation for the operator versions and there's no docstring. In particular, how is __add__ different from add? Because they're implemented differently, and you can't be sure that a + b and a.add(b) will return the same result by inspecting the code.
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the master branch of pandas.
Reproducible Example
Issue Description
I'm marked this as a bug because I am under the impression that this worked as I expected in a previous version, but I can't be sure.
I had assumed that this operator would intelligently align the series with the columns of the data frame, since the index of the series is the same object as the index of the dataframe, rather than defaulting to
axis="columns"
as for theadd
method.Above gives
It feels like the operator versions of the binary operations could have the additional logic to attempt to intelligently choose which axis to use to broadcast when operating on a dataframe and a series. If you need to specific the axis for speed or because it's possible to make the wrong choice, then I think it's OK to expect people to use the method version.
However, if this is the intended behaviour, then it's probably worth adding something in the docs. In fact, I can't find any documentation for the operator versions and there's no docstring. In particular, how is
__add__
different fromadd
? Because they're implemented differently, and you can't be sure thata + b
anda.add(b)
will return the same result by inspecting the code.Expected Behavior
Like
only since
Installed Versions
The text was updated successfully, but these errors were encountered: