-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
RecursionError when aligning DataFrames based on MultiIndex with different order of names #25760
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
Comments
I'm not sure if we make any requirements around the ordering of levels in a MultiIndex - @mroeschke any thoughts here? |
One issue is that if this arithmetic is allowed which solution should this op return? I think this case is ambiguous and would opt to raise in this case - a more informative error message in this case. |
If all operations after that "align on both row and column labels" as documentation says, then picking which to return is not important. It's like picking which order to use for lists that represent sets. Another option is to change behavior of align - currently it puts common columns before others. It's a problem because even if I try to use a consistent order of columns in my application, it gets jumbled by operations that use align. E.g., if I have |
Just ran into this. I ended up having to write a workaround like this: def align_levels(ref, obj):
"""Return a copy of *obj* with common levels in the same order as *ref*."""
# Common levels in the same order as ref
common = [n for n in ref.index.names if n in obj.index.names]
# Levels only appearing on obj
unique = [n for n in obj.index.names if n not in common]
# Return copy with new level order
return obj.reorder_levels(common + unique)
x * align_levels(x, y) |
I looked a little bit at the source code, and I think the cause of this is the following: Possible Cause of the IssueIn Then in For the same set of names but in the wrong order, the recursion keeps alternating between QuestionConsidering that there isn't any decision as to how this should work, would it be possible to check if the neither of the indexes changed in |
Code Sample, a copy-pastable example if possible
Problem description
RecursionError in align()/join().
The ideal expected behavior is to calculate the sum.
If different orders of names in MultiIndex are not supported by design, then a clear error message stating that would be preferable to RecursionError.
Expected Output
or
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.7.1.final.0
python-bits: 64
OS: Linux
OS-release: 4.9.125-linuxkit
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.24.2
pytest: None
pip: 19.0.3
setuptools: 40.8.0
Cython: 0.29.6
numpy: 1.15.4
scipy: 1.2.1
pyarrow: None
xarray: None
IPython: 7.3.0
sphinx: None
patsy: 0.5.1
dateutil: 2.8.0
pytz: 2018.9
blosc: None
bottleneck: None
tables: None
numexpr: 2.6.9
feather: None
matplotlib: 3.0.3
openpyxl: None
xlrd: 1.2.0
xlwt: None
xlsxwriter: None
lxml.etree: None
bs4: 4.7.1
html5lib: None
sqlalchemy: 1.3.1
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None
The text was updated successfully, but these errors were encountered: