-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Description
Sometimes it would be nice for isel()
to be able to ignore a dimension if it is missing in the Dataset/DataArray. E.g.
ds = Dataset()
ds.isel(t=0) # currently raises an exception
ds.isel(t=0, ignore_missing=True) # would be nice if this was allowed, just returning ds
For example, when writing a function can be called on variables with different combinations of dimensions.
I think it should be fairly easy to implement, just add the argument to the condition here
xarray/xarray/core/variable.py
Lines 1059 to 1062 in 65a5bff
if invalid: | |
raise ValueError( | |
f"dimensions {invalid} do not exist. Expected one or more of {self.dims}" | |
) |
the only downside would be increased complexity of adding another argument to the API for an issue where a workaround is not hard (at least in the case I have at the moment), just a bit clumsy.