Fix xarray inferred-from data ordering - #8445
Conversation
|
@microsoft-github-policy-service agree company="Microsoft" |
6029ed8 to
820eb16
Compare
permuted data axis. Fixing ordering of data when using permuted data axes Revert "Updating documentation" This reverts commit 60a4735. Fixing linting
820eb16 to
93cb275
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8445 +/- ##
==========================================
+ Coverage 71.12% 71.14% +0.02%
==========================================
Files 305 305
Lines 31952 31973 +21
==========================================
+ Hits 22725 22748 +23
+ Misses 9227 9225 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes ordering issues when exporting QCoDeS datasets to xarray in cases where data acquisition order is permuted relative to the inferred grid structure, and when inferred-from parameters need to be exported consistently alongside reordered data.
Changes:
- Add an
indexplumbing path to_add_inferred_data_varsto support order-aware insertion of inferred-from variables in the pandas→xarray export route. - Rework the direct-to-xarray export (
_xarray_data_set_direct) to derive coordinate axes and reorder data based on the actual dependency arrays rather than relying on shape-based axis inference. - Extend test coverage to validate permuted-grid ordering, direct-export grid validation, and inferred handling.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/qcodes/dataset/exporters/export_to_xarray.py |
Adds index-aware inferred var insertion and reimplements direct xarray export ordering/reconstruction logic. |
tests/dataset/test_dataset_export.py |
Adds regression + validation tests for permuted direct export and _xarray_data_set_direct input validation. |
tests/dataset/test_inferred_multiple_parents.py |
Updates direct calls to _add_inferred_data_vars for the new index argument. |
tests/dataset/test_parameter_with_setpoints_has_control.py |
Updates _add_inferred_data_vars invocation to pass index=None. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if index is not None: | ||
| # If an index is provided, we should align the inferred data with the index. | ||
| # This is necessary because data may be reordered when transforming from a pandas DataFrame to an xarray Dataset. | ||
| # Passing an index allows the original data ordering to be preserved on reconstruction. | ||
| indexed_data = Series(flat, index=index, name=inf.name).to_xarray() | ||
| xr_dataset[inf.name] = indexed_data | ||
| else: | ||
| xr_dataset[inf.name] = (dims, flat.reshape(expected_shape)) |
|
One or more custom setup steps configured for this repository failed during this Copilot code review run: Setup steps run before each review. If the review above is missing context, or no review was posted at all, the failing step above may be the cause. See the workflow run for failure details, fix your setup steps configuration, and re-request a review. Note You can configure setup steps for Copilot code review separately from Copilot cloud agent with a |
Dataset export to xarray currently fails under the condition.
This can occur when array-valued parameters. Users may wish to acquire and save data in a particular order, and no assumptions.
This failure occurs in two cases: