Fix AlignmentError in to_xarray_dataset when data variables have different setpoints#8244
Draft
Copilot wants to merge 2 commits into
Draft
Fix AlignmentError in to_xarray_dataset when data variables have different setpoints#8244Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8244 +/- ##
==========================================
+ Coverage 71.02% 71.03% +0.01%
==========================================
Files 301 301
Lines 31888 31900 +12
==========================================
+ Hits 22647 22659 +12
Misses 9241 9241 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
… xarray When a dataset has two data variables with different setpoints, and one is a non-grid array parameter (using the multi_index path) while another shares a setpoint coordinate as a standalone dimension, xr.merge raised an AlignmentError because the shared coordinate had conflicting Index objects in the two sub-datasets. Fix: detect this conflict in load_to_xarray_dataset and unstack the multi_index into proper independent dimensions before merging, allowing the shared coordinate to be consistent across all sub-datasets. Fixes #8232 Co-authored-by: jenshnielsen <548266+jenshnielsen@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix export to xarray dataset when data variables have different setpoints
Fix AlignmentError in to_xarray_dataset when data variables have different setpoints
Jun 24, 2026
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.
DataSet.to_xarray_dataset()raises anAlignmentErrorwhen two data variables share a setpoint coordinate but one of them has additional non-grid setpoints (triggering the multi-index export path).Root cause: Per-parameter sub-datasets are built independently. A non-grid array parameter (e.g.
spectrumwith setpoints(f_stop, freq)where freq values differ per sweep point) gets exported viaxr.Coordinates.from_pandas_multiindex, makingf_stopa component of a MultiIndex rather than a standalone dimension. A co-registered scalar parameter with only(f_stop,)gets a plainPandasIndexforf_stop.xr.mergecannot align these incompatible Index objects.Fix (
export_to_xarray.py):xr.merge, detect sub-datasets that use amulti_indexdimension whose coordinate levels conflict with standalone dimensions in other sub-datasetsds.unstack("multi_index")on the conflicting sub-datasets, converting to regular independent dimensions (NaN-filling off-grid entries) so all sub-datasets share a consistentf_stopcoordinate structureTest (
test_dataset_export.py):f_stopover two values with differing frequency grids, verifying bothspectrum(2-D, NaN-padded) andbar(1-D) are correctly present with values preserved in the merged dataset