Skip to content

Allow isel to ignore missing dimensions? #3866

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

Closed
johnomotani opened this issue Mar 17, 2020 · 0 comments · Fixed by #3923
Closed

Allow isel to ignore missing dimensions? #3866

johnomotani opened this issue Mar 17, 2020 · 0 comments · Fixed by #3923

Comments

@johnomotani
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants