BUG: Series.add(DataFrame) fails to align (original) (raw)

Pandas version checks

Reproducible Example

import pandas as pd

df = pd.DataFrame( {2010: [1], 2020: [3]}, index=pd.MultiIndex.from_product( [["a"], ["b"]], names=["scen", "mod"] ), )

s = pd.Series( [10., 20., 30.], index=pd.MultiIndex.from_product([["a"], ["b"], [0, 1, 2]], names=["scen", "mod", "id"]), )

print(s.add(df, axis=0))

Issue Description

The addition operation fails with

Traceback (most recent call last):
  File "/home/jmu3si/tmp/addtest.py", line 15, in <module>
    print(s.add(df, axis=0))
  File "/home/jmu3si/Devel/pandas/pandas/core/ops/__init__.py", line 197, in flex_wrapper
    return op(self, other)
  File "/home/jmu3si/Devel/pandas/pandas/core/ops/common.py", line 70, in new_method
    return method(self, other)
  File "/home/jmu3si/Devel/pandas/pandas/core/arraylike.py", line 104, in __radd__
    return self._arith_method(other, roperator.radd)
  File "/home/jmu3si/Devel/pandas/pandas/core/frame.py", line 7019, in _arith_method
    self, other = ops.align_method_FRAME(self, other, axis, flex=True, level=None)
  File "/home/jmu3si/Devel/pandas/pandas/core/ops/__init__.py", line 307, in align_method_FRAME
    left, right = left.align(
  File "/home/jmu3si/Devel/pandas/pandas/core/frame.py", line 4719, in align
    return super().align(
  File "/home/jmu3si/Devel/pandas/pandas/core/generic.py", line 8872, in align
    return self._align_series(
  File "/home/jmu3si/Devel/pandas/pandas/core/generic.py", line 8989, in _align_series
    join_index, lidx, ridx = join_index.join(
  File "/home/jmu3si/Devel/pandas/pandas/core/indexes/base.py", line 221, in join
    join_index, lidx, ridx = meth(self, other, how=how, level=level, sort=sort)
  File "/home/jmu3si/Devel/pandas/pandas/core/indexes/base.py", line 4541, in join
    return self._join_multi(other, how=how)
  File "/home/jmu3si/Devel/pandas/pandas/core/indexes/base.py", line 4662, in _join_multi
    raise ValueError("cannot join with no overlapping index names")
ValueError: cannot join with no overlapping index names

Expected Behavior

The s.add(df, axis=0) should yield the same result as df.add(s, axis=0) which results in

             2010  2020
scen mod id            
a    b   0   11.0  13.0
         1   21.0  23.0
         2   31.0  33.0

Installed Versions

INSTALLED VERSIONS ------------------ commit : d801a4bpython : 3.9.7.final.0 python-bits : 64 OS : Linux OS-release : 5.4.0-100-lowlatency Version : #113-Ubuntu SMP PREEMPT Thu Feb 3 19:24:13 UTC 2022 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : de_DE.UTF-8 LOCALE : de_DE.UTF-8

pandas : 1.5.0.dev0+443.gd801a4b19d
numpy : 1.21.4
pytz : 2021.3
dateutil : 2.8.2
pip : 21.2.4
setuptools : 58.0.4
Cython : 0.29.24
pytest : 6.2.5
hypothesis : 6.24.6
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.0.2
lxml.etree : 4.8.0
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 3.0.3
IPython : 7.29.0
pandas_datareader: None
bs4 : 4.10.0
bottleneck : None
fastparquet : None
fsspec : 2022.01.0
gcsfs : None
markupsafe : 2.0.1
matplotlib : 3.5.1
numba : 0.55.1
numexpr : 2.8.1
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : 7.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.8.0
sqlalchemy : 1.4.31
tables : 3.7.0
tabulate : None
xarray : 0.21.1
xlrd : 2.0.1
xlwt : 1.3.0
zstandard : None