Skip to content

Conversation

snitish
Copy link
Member

@snitish snitish commented Feb 28, 2025

…ion in case of different levels

In case of arithmetic operations between a DataFrame with MultiIndex columns and a Series, if the two multiindexes don't have the same levels, the output values are all nan (see example in the original issue).
A similar issue for DataFrame-DataFrame arithmetic operations was fixed in #60538. This PR addresses the bug in the DataFrame-Series case with axis=1 (i.e. aligning DataFrame columns with Series MultiIndex).

The fix itself is simple - we just use

right = other._reindex_indexer(join_index, ridx)

instead of

right = other.reindex(join_index, level=level)

because Series.reindex needs the new MultiIndex to have identical levels to the current index. Instead, we simply use the ridx object that we already have from a previous Index.join call, which does handle partially overlapping levels well.

@mroeschke mroeschke added this to the 3.0 milestone Feb 28, 2025
@mroeschke mroeschke merged commit c28c589 into pandas-dev:main Feb 28, 2025
50 checks passed
@mroeschke
Copy link
Member

Thanks @snitish

@snitish snitish deleted the issue61009 branch February 28, 2025 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: .mul on multi index columns doesnt work.

2 participants