From f9f13ee46482c370114e9021d88582bae04b9119 Mon Sep 17 00:00:00 2001 From: Peter Beaucage Date: Tue, 7 May 2024 18:28:49 -0400 Subject: [PATCH] Fix bug: xarray Dataset data variables/coordinates don't have attributes populated (#736) * test: validate xarray names and attributes Co-authored-by: Tyler Martin * Fetch/use metadata when creating xarray vars/coords Co-authored-by: Tyler Martin * update changelog * Fix lint --------- Co-authored-by: Tyler Martin Co-authored-by: AFL --- CHANGELOG.md | 1 + tiled/_tests/test_xarray.py | 2 +- tiled/client/xarray.py | 14 ++++++++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45fe964be..3667f0275 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/tiled/_tests/test_xarray.py b/tiled/_tests/test_xarray.py index 71221fde9..b6738824e 100644 --- a/tiled/_tests/test_xarray.py +++ b/tiled/_tests/test_xarray.py @@ -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): diff --git a/tiled/client/xarray.py b/tiled/client/xarray.py index a80f287aa..399c2a5ac 100644 --- a/tiled/client/xarray.py +++ b/tiled/client/xarray.py @@ -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( @@ -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 "