Skip to content

Commit

Permalink
Fix bug: xarray Dataset data variables/coordinates don't have attribu…
Browse files Browse the repository at this point in the history
…tes populated (#736)

* test: validate xarray names and attributes

Co-authored-by: Tyler Martin <tyler.martin@nist.gov>

* Fetch/use metadata when creating xarray vars/coords

Co-authored-by: Tyler Martin <tyler.martin@nist.gov>

* update changelog

* Fix lint

---------

Co-authored-by: Tyler Martin <tyler.martin@nist.gov>
Co-authored-by: AFL <afl@saxsbot.com>
  • Loading branch information
3 people authored May 7, 2024
1 parent 88f4f5f commit f9f13ee
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Write the date in place of the "Unreleased" in the case a new version is release
### Fixed

- Propagate setting `include_data_sources` into child nodes.
- Populate attributes in member data variables and coordinates of xarray Datasets.

## v0.1.0a120 (25 April 2024)

Expand Down
2 changes: 1 addition & 1 deletion tiled/_tests/test_xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def client():
def test_xarray_dataset(client, key):
expected = EXPECTED[key]
actual = client[key].read().load()
xarray.testing.assert_equal(actual, expected)
xarray.testing.assert_identical(actual, expected)


def test_specs(client):
Expand Down
14 changes: 12 additions & 2 deletions tiled/client/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ def _build_arrays(self, variables, optimize_wide_table):
coords[name] = (
array_client.dims,
coords_fetcher.register(name, array_client, array_structure),
array_client.metadata["attrs"],
)
elif "xarray_data_var" in spec_names:
data_vars[name] = (
array_client.dims,
data_vars_fetcher.register(name, array_client, array_structure),
array_client.metadata["attrs"],
)
else:
raise ValueError(
Expand All @@ -88,9 +90,17 @@ def _build_arrays(self, variables, optimize_wide_table):
)
else:
if "xarray_coord" in spec_names:
coords[name] = (array_client.dims, array_client.read())
coords[name] = (
array_client.dims,
array_client.read(),
array_client.metadata["attrs"],
)
elif "xarray_data_var" in spec_names:
data_vars[name] = (array_client.dims, array_client.read())
data_vars[name] = (
array_client.dims,
array_client.read(),
array_client.metadata["attrs"],
)
else:
raise ValueError(
"Child nodes of xarray_dataset should include spec "
Expand Down

0 comments on commit f9f13ee

Please sign in to comment.