Skip to content

Fix inferred parameter export when index cannot be expanded - #8454

Open
Jens Hedegaard Nielsen (jenshnielsen) wants to merge 1 commit into
microsoft:aaron/fix-xarray-inferred-from-orderingfrom
jenshnielsen:xarray_export_copilot_comment
Open

Fix inferred parameter export when index cannot be expanded#8454
Jens Hedegaard Nielsen (jenshnielsen) wants to merge 1 commit into
microsoft:aaron/fix-xarray-inferred-from-orderingfrom
jenshnielsen:xarray_export_copilot_comment

Conversation

@jenshnielsen

Copy link
Copy Markdown
Collaborator

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.

`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
@codecov

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.14%. Comparing base (b4ac0b4) to head (5aea2ca).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant