Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ def __init__(self, coordinate: Hashable, skip_missing: bool = False):
self._skip_missing = skip_missing

def apply_func(self, dataset: xr.Dataset) -> xr.Dataset:
discovered_coord = list(set(self._coordinate).intersection(set(dataset.coords)))

if len(discovered_coord) == 0:
if self._coordinate not in dataset.coords:
if self._skip_missing:
return dataset

Expand All @@ -153,7 +151,7 @@ def apply_func(self, dataset: xr.Dataset) -> xr.Dataset:
"Set 'skip_missing' to True to skip this."
)

discovered_coord = str(discovered_coord[0])
discovered_coord = self._coordinate

coords = dataset.coords
new_ds = xr.Dataset(coords={co: v for co, v in coords.items() if not co == discovered_coord})
Expand All @@ -179,7 +177,7 @@ def apply_func(self, dataset: xr.Dataset) -> xr.Dataset:

selected = dataset[var].sel(**{discovered_coord: coord_val}) # type: ignore
selected = selected.drop_vars(discovered_coord) # type: ignore
selected.attrs.update(**{discovered_coord: coord_val})
selected.attrs.update(**{str(discovered_coord): coord_val})
Copy link
Collaborator

@nikeethr nikeethr Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for the explicit string representation? Would it be better to let it error out if it is (unexpectedly) not a string? If this is how its done everywhere else, then just ignore this comment.


new_ds[f"{var}{coord_val}"] = selected
return new_ds
Expand Down
Loading