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

Follow keep_attrs in Dataset binary ops #7391

Merged
merged 11 commits into from
Jan 26, 2023

Conversation

arongergely
Copy link
Contributor

@arongergely arongergely commented Dec 19, 2022

Should I describe in whats-new.rst?

Copy link
Collaborator

@keewis keewis left a comment

Choose a reason for hiding this comment

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

thanks for the PR, @arongergely, and sorry for the delayed reply.

If possible I'd like to change the computation of the attrs of the result a bit to allow more than just bool values (see below).

And yes, a entry to whats-new.rst would be great (section "Bug fixes").

xarray/core/dataset.py Show resolved Hide resolved
xarray/tests/test_dataset.py Outdated Show resolved Hide resolved
@arongergely
Copy link
Contributor Author

Thanks for your suggestions @keewis!

If possible I'd like to change the computation of the attrs of the result a bit to allow more than just bool values (see below).

I was puzzled initially. We would introduce the combine_attrs behaviour of xarray.merge() but under keep_attrs.
Then I found out this is already a thing in apply_ufunc().

I like the idea, shouldn't we

  • implement this for xarray.Variable too?
  • consider this as new feature, not just a bugfix? (for describing in whats-new.rst)
  • describe in the documentation? (also for apply_ufunc() - it's not yet described there).

could do all these, let me know

@keewis
Copy link
Collaborator

keewis commented Jan 11, 2023

The missing documentation for this in apply_ufunc is definitely an oversight, so PRs very welcome!

consider this as new feature, not just a bugfix?

I always struggle with classifying changes, but I guess the more we add onto this PR, the more it becomes a new feature.

implement this for xarray.Variable too?

probably. The only reason this is not done yet is because nobody took the time to actually do it. So, once again: PRs very welcome!

Copy link
Contributor Author

@arongergely arongergely left a comment

Choose a reason for hiding this comment

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

@arongergely
Copy link
Contributor Author

arongergely commented Jan 16, 2023

Hit a roadblock.

For binary ops the only way to set keep_attrs is through the options.
However we can not set combine_attrs style strings to it due to strict validation.
So this would lead to an error:

with xr.set_options(keep_attrs="drop_conflicts"):
   ds1 + ds2

To cricle around this we could let keep_attrs passed in the operator methods so user could do:

ds1.__add__(ds2, keep_attrs="drop_conflicts")

But this isn't "nice".

Or perhaps I missed something?

@arongergely
Copy link
Contributor Author

Changing the option setters to accept combine_attrs-style strings would open room for silent bugs:
Other funcs/operators assume keep_attrs to be boolean so an if keep_attrs would cause trouble.

@keewis
Copy link
Collaborator

keewis commented Jan 16, 2023

I guess this means that we have two options: just assume this does not cause anything else to fail to get this PR to work (but then this PR would be blocked until we fixed every use of the global keep_attrs in a separate PR), or we ignore str-valued / callable keep_attrs for now and merge your initial proposal.

Option 2 seems easier, so I'd suggest we go with that?

@arongergely
Copy link
Contributor Author

arongergely commented Jan 16, 2023

Option 2 seems easier, so I'd suggest we go with that?

Agreed!

@arongergely
Copy link
Contributor Author

Will you cherry pick?

@arongergely
Copy link
Contributor Author

maybe not. I changed it back so you could squash to exclude the noise.
The test is adjusted accordingly.

Copy link
Collaborator

@keewis keewis left a comment

Choose a reason for hiding this comment

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

Thanks, @arongergely. We always squash-merge so this is basically what I would have done.

@dcherian
Copy link
Contributor

Thanks @arongergely !

@dcherian dcherian added the plan to merge Final call for comments label Jan 25, 2023
@dcherian dcherian changed the title Dataset binary op keep attrs Follow keep_attrs in Dataset binary ops Jan 25, 2023
@dcherian dcherian merged commit 97d7e76 into pydata:main Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plan to merge Final call for comments
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dataset binary ops ignore keep_attrs option
3 participants