Fix inferred parameter export when index cannot be expanded - #8454
Open
Jens Hedegaard Nielsen (jenshnielsen) wants to merge 1 commit into
Conversation
`Series(...).to_xarray()` expands a pandas index into one dimension per index level. That is only compatible with the target xarray dataset when the dataset dimensions are exactly the levels of the index. It is not the case when the dataset uses a single `multi_index` dimension or the flat index created by `DataFrame.reset_index()`, and a non unique MultiIndex cannot be converted at all. Only take the reindexing path when the index is unique and the dataset dimensions match the index level names. In the remaining cases the data is already in index order and can be reshaped directly. Adds tests covering export of an inferred parameter with a `multi_index` dimension and with a non unique MultiIndex. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 92aac34d-1a70-4ca9-900c-4ab563a731df
Jens Hedegaard Nielsen (jenshnielsen)
requested a review
from a team
as a code owner
August 27, 2026 08:49
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## aaron/fix-xarray-inferred-from-ordering #8454 +/- ##
========================================================================
Coverage 71.14% 71.14%
========================================================================
Files 305 305
Lines 31973 31974 +1
========================================================================
+ Hits 22748 22749 +1
Misses 9225 9225 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Series(...).to_xarray()expands a pandas index into one dimension per index level. That is only compatible with the target xarray dataset when the dataset dimensions are exactly the levels of the index. It is not the case when the dataset uses a singlemulti_indexdimension or the flat index created byDataFrame.reset_index(), and a non unique MultiIndex cannot be converted at all.Only take the reindexing path when the index is unique and the dataset dimensions match the index level names. In the remaining cases the data is already in index order and can be reshaped directly.
Adds tests covering export of an inferred parameter with a
multi_indexdimension and with a non unique MultiIndex.