Skip to content

Commit 6fc7609

Browse files
authored
Don't look for T in sgrid axes (#435)
* hopeful simple fix for issue cf-xarray is not finding T as a time axis due to a KeyError. This first checks to see if the key is in sgrid_axes before using that. * added test which led to a change in code
1 parent 782c9e3 commit 6fc7609

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

cf_xarray/accessor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def _get_axis_coord(obj: DataArray | Dataset, key: str) -> list[str]:
321321
if units in expected:
322322
results.update((coord,))
323323

324-
if key in _AXIS_NAMES and "grid_topology" in obj.cf.cf_roles:
324+
if key in ["X", "Y", "Z"] and "grid_topology" in obj.cf.cf_roles:
325325
sgrid_axes = sgrid.parse_axes(obj)
326326
results.update((search_in | set(obj.dims)) & sgrid_axes[key])
327327

cf_xarray/tests/test_accessor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,12 +1878,14 @@ def test_grid_topology() -> None:
18781878
ds = xr.Dataset(
18791879
data_vars={},
18801880
coords={
1881+
"time": ("time", [1, 2, 3], {"standard_name": "time"}),
18811882
"mesh": (tuple(), 1, {"cf_role": "mesh_topology"}),
18821883
"grid": (tuple(), 1, {"cf_role": "grid_topology"}),
18831884
},
18841885
)
18851886
assert_identical(ds.cf["grid_topology"], ds.grid.reset_coords(drop=True))
18861887
assert_identical(ds.cf["mesh_topology"], ds.mesh.reset_coords(drop=True))
1888+
assert "T" in ds.cf.axes
18871889

18881890

18891891
@requires_scipy

0 commit comments

Comments
 (0)