Skip to content
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

Drop missing variables #267

Merged
merged 8 commits into from
Dec 7, 2021
Merged

Conversation

malmans2
Copy link
Member

@malmans2 malmans2 commented Nov 24, 2021

Closes #254

I haven't tried with other attributes, but it looks like introducing a decorator that only returns existing keys would work well.
Thoughts? If you think that this is the way to go, I'll try to implement it for cell_measures, formula_terms, ...

cc: @dcherian @tomvothecoder @huard

@dcherian
Copy link
Contributor

Thanks @malmans2 I'd prefer a simple function that dropped nonexistent variables. It seems much easier to interpret and maintain. So something like return self._drop_missing_variables(results)

@malmans2 malmans2 changed the title introduce _must_exist decorator Drop missing variables Nov 24, 2021
_variables(_single(_must_exist(_get_bounds))), self._obj, key
)[0]
results = self.bounds.get(key, [])
_raise_if_not_single(key, results)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if this is right. For a staggered grid you could have multiple lat/lon with different bounds though I don't know that anyone ever does that :)

Copy link
Member Author

@malmans2 malmans2 Nov 24, 2021

Choose a reason for hiding this comment

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

Mmmm, not sure. I think we would have to change how we pare da.attrs['bounds'], because I think right now we assume it's a single string.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ohh actually you're right, for example key="longitude" could be associated to multiple bounds. The problem is that I think other functions use this and need a single DataArray. Maybe it's better to address this in a separate PR...

Copy link
Contributor

Choose a reason for hiding this comment

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

Lets open an issue for that. And here lets not raise_if_single...

@malmans2
Copy link
Member Author

This should be good to go!

@malmans2 malmans2 requested a review from dcherian December 6, 2021 17:37
@dcherian dcherian merged commit 6f47339 into xarray-contrib:main Dec 7, 2021
@dcherian
Copy link
Contributor

dcherian commented Dec 7, 2021

Thanks Mattia

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

Successfully merging this pull request may close these issues.

Remove nonexistent variable names from properties like bounds, cell_measures, formula_terms
3 participants