-
Notifications
You must be signed in to change notification settings - Fork 4
Store dataset properties in netCDF-safe attrs with backward-compatible reads, add CI test workflow, and include optional IFS dependencies #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
observingClouds
merged 15 commits into
main
from
copilot/fix-properties-dataset-attribute
May 22, 2026
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2dac041
Initial plan
Copilot 8226a6c
fix: store dataset properties in netcdf-compatible attrs
Copilot 7885b59
test: close netcdf dataset handle in properties attr test
Copilot 605b283
refactor: use dotted properties attr keys
Copilot 9ece8b5
refactor: drop underscore properties attr fallback
Copilot 3bdf9bf
style: apply ruff format fix
Copilot f596fe1
ci: add workflow to run unit tests
Copilot 37518b4
ci: use uv lockfile for test workflow
Copilot bf7c3b6
build: add ifs optional deps and install all extras in CI
Copilot 399df31
build: add eccodes to ifs optional dependency group
Copilot 7216c8e
build: add eccodeslib to ifs optional dependencies
Copilot 90d14ba
Add changelog entry for PR 21 changes
Copilot b8e96fa
Apply suggestion from @observingClouds
observingClouds c4b9088
use pytest instead of unittest
observingClouds fdc412c
remove unittest
observingClouds File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| name: Test Suite | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: [main, develop] | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| unit-tests: | ||
| name: Run Unit Tests | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - uses: astral-sh/setup-uv@v6 | ||
| with: | ||
| python-version: "3.12" | ||
| - name: Install dependencies | ||
| run: uv sync --frozen --all-extras | ||
| - name: Run tests | ||
| run: uv run pytest tests -v |
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import json | ||
| import tempfile | ||
|
|
||
| import xarray as xr | ||
|
|
||
| from mxalign.properties.properties import Properties, Space, Time, Uncertainty | ||
| from mxalign.properties.utils import properties_from_attrs, set_properties_attrs | ||
|
|
||
|
|
||
| class TestPropertiesAttrs: | ||
| def test_properties_are_stored_in_netcdf_compatible_attrs(self): | ||
| ds = xr.Dataset() | ||
| props = Properties( | ||
| space=Space.POINT, | ||
| time=Time.OBSERVATION, | ||
| uncertainty=Uncertainty.DETERMINISTIC, | ||
| ) | ||
|
|
||
| ds = set_properties_attrs(ds, props) | ||
|
|
||
| assert "properties" not in ds.attrs | ||
| assert ds.attrs["properties.space"] == "point" | ||
| assert ds.attrs["properties.time"] == "observation" | ||
| assert ds.attrs["properties.uncertainty"] == "deterministic" | ||
|
|
||
| with tempfile.NamedTemporaryFile(suffix=".nc") as tmp: | ||
| ds.to_netcdf(tmp.name) | ||
| with xr.open_dataset(tmp.name) as ds_loaded: | ||
| assert properties_from_attrs(ds_loaded) == props | ||
|
|
||
| def test_properties_can_still_be_read_from_legacy_format(self): | ||
| ds = xr.Dataset() | ||
| ds.attrs["properties"] = { | ||
| "space": "point", | ||
| "time": "observation", | ||
| "uncertainty": "deterministic", | ||
| } | ||
| assert properties_from_attrs(ds) == Properties( | ||
| space=Space.POINT, | ||
| time=Time.OBSERVATION, | ||
| uncertainty=Uncertainty.DETERMINISTIC, | ||
| ) | ||
|
|
||
| def test_properties_can_be_read_from_legacy_json_string(self): | ||
| ds = xr.Dataset() | ||
| ds.attrs["properties"] = json.dumps( | ||
| {"space": "point", "time": "observation", "uncertainty": "deterministic"} | ||
| ) | ||
| assert properties_from_attrs(ds) == Properties( | ||
| space=Space.POINT, | ||
| time=Time.OBSERVATION, | ||
| uncertainty=Uncertainty.DETERMINISTIC, | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.