Skip to content

Commit e62b9a5

Browse files
committed
Fix unit tests
1 parent 3ee00ad commit e62b9a5

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

e3sm_diags/driver/utils/dataset_xr.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ def _get_climo_dataset(self, season: str) -> xr.Dataset:
414414
return ds
415415

416416
def _add_cf_attrs_to_z_axes(self, ds: xr.Dataset) -> xr.Dataset:
417-
"""Add CF attributes to the Z axes of the dataset.
417+
"""Add CF attributes to the Z axis of the dataset if the Z axis exists.
418418
419419
This method is a temporary solution to enable xCDAT to properly
420420
retrieve bounds for Z axes that do not have CF attributes, which
@@ -430,12 +430,15 @@ def _add_cf_attrs_to_z_axes(self, ds: xr.Dataset) -> xr.Dataset:
430430
xr.Dataset
431431
The dataset with CF attributes added to the Z axes.
432432
"""
433-
dim = xc.get_dim_keys(ds, axis="Z")
434-
435-
axis_attr = ds[dim].attrs.get("axis")
433+
try:
434+
dim = xc.get_dim_keys(ds, axis="Z")
435+
except KeyError:
436+
pass
437+
else:
438+
axis_attr = ds[dim].attrs.get("axis")
436439

437-
if axis_attr is None:
438-
ds[dim].attrs["axis"] = "Z"
440+
if axis_attr is None:
441+
ds[dim].attrs["axis"] = "Z"
439442

440443
return ds
441444

0 commit comments

Comments
 (0)