-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Change behavior of keep_attrs in xr.where when x is a scalar
#10997
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
Conversation
keep_attrs in xr.where when x is a scalar
keewis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me now (and the trick with _replace is interesting, I didn't know that existed). You might want to add a entry to whats-new.rst under "bug fixes", though.
Yeah I will add. I am also updating the |
|
Thanks for the reviews @keewis! I will merge this when it passes unless you have more feedback. |
keewis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some comments on the docstring changes
xarray/computation/computation.py
Outdated
| keep_attrs : bool or str or callable, optional | ||
| How to treat attrs. If True, keep the attrs of `x`. | ||
| keep_attrs : bool or {"drop", "identical", "no_conflicts", "drop_conflicts", "override"} or callable, optional | ||
| - 'drop' or False (default): empty attrs on returned xarray object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
False is not the default, we pull the default from OPTIONS["keep_attrs"] (which we might have changed to True by now?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops! Maybe I should move True up to be first in the list as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case True is the default when OPTIONS["keep_attrs"] in (True, "default")
xarray/computation/computation.py
Outdated
| Coordinates: | ||
| * lat (lat) int64 80B 0 1 2 3 4 5 6 7 8 9 | ||
| Preserve the attrs on `cond` by using `keep_attrs="drop_conflicts"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a side-effect of there being no attributes on scalars (so it may be worth pointing that out). If we want to do that exactly for all cases, we'd have to use a lambda / a function: keep_attrs=lambda attrs: attrs[0] if attrs else {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ymm yeah. I tried to make it clearer that this is specifically for the case where x is a scalar.
keewis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, this looks good to me now!
xarray.wherefor coordinate attributes #10982whats-new.rstBased on how
keep_attrs=Falsebehaves in other methods, I think it should drop all attrs.Demo