Skip to content
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

Update get_bounds() to support mappable non-CF axes using "bounds" attr #708

Merged
merged 8 commits into from
Oct 8, 2024
Next Next commit
Add tests for updated logic
tomvothecoder committed Oct 7, 2024
commit d9a140a814e40c8a812482c14449c65feefd3cf3
53 changes: 53 additions & 0 deletions tests/test_bounds.py
Original file line number Diff line number Diff line change
@@ -287,6 +287,27 @@ def test_returns_single_dataset_axis_bounds_as_a_dataarray_object(self):

assert result.identical(expected)

def test_returns_single_dataset_axis_bounds_as_a_dataarray_object_for_non_cf_axis(
self,
):
ds = xr.Dataset(
coords={
"lat": xr.DataArray(
data=np.ones(3),
dims="lat",
attrs={"bounds": "lat_bnds"},
)
},
data_vars={
"lat_bnds": xr.DataArray(data=np.ones((3, 3)), dims=["lat", "bnds"])
},
)

result = ds.bounds.get_bounds("Y")
expected = ds.lat_bnds

assert result.identical(expected)

def test_returns_multiple_dataset_axis_bounds_as_a_dataset_object(self):
ds = xr.Dataset(
coords={
@@ -321,6 +342,38 @@ def test_returns_multiple_dataset_axis_bounds_as_a_dataset_object(self):

assert result.identical(expected)

def test_returns_multiple_dataset_axis_bounds_as_a_dataset_object_for_non_cf_axis(
self,
):
ds = xr.Dataset(
coords={
"lat": xr.DataArray(
data=np.ones(3),
dims="lat",
attrs={
"bounds": "lat_bnds",
},
),
"lat2": xr.DataArray(
data=np.ones(3),
dims="lat2",
attrs={
"bounds": "lat2_bnds",
},
),
},
data_vars={
"var": xr.DataArray(data=np.ones(3), dims=["lat"]),
"lat_bnds": xr.DataArray(data=np.ones((3, 3)), dims=["lat", "bnds"]),
"lat2_bnds": xr.DataArray(data=np.ones((3, 3)), dims=["lat2", "bnds"]),
},
)

result = ds.bounds.get_bounds("Y")
expected = ds.drop_vars("var")

assert result.identical(expected)


class TestAddBounds:
@pytest.fixture(autouse=True)