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

also apply combine_attrs to the attrs of the variables #4902

Merged
merged 31 commits into from
May 5, 2021

Conversation

keewis
Copy link
Collaborator

@keewis keewis commented Feb 12, 2021

Follow-up to #4827. The current behavior is to always combine with combine_attrs="override", even if the caller requested something else.

@keewis
Copy link
Collaborator Author

keewis commented Feb 13, 2021

I tried to fix the tests but the remaining failures in test_backends (open_mfdataset) are due to the expectation that combine_attrs="drop" only drops attrs on the main object.

@@ -272,7 +282,7 @@ def test_merge_no_conflicts_multi_var(self):

def test_merge_no_conflicts_preserve_attrs(self):
data = xr.Dataset({"x": ([], 0, {"foo": "bar"})})
actual = xr.merge([data, data])
actual = xr.merge([data, data], combine_attrs="no_conflicts")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

does this make sense? I think the no_conflicts refers to compat and not combine_attrs, but otherwise this will keep failing.

#4749 suggested to change the default merge strategy to drop_conflicts, so we could revert all these tiny test changes after that (but maybe we need to deprecate the current default first?)

Copy link
Contributor

Choose a reason for hiding this comment

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

is the old default "override"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes. This is done by compat, which delegates to fillna, which in turn calls apply_ufunc. This raises the bigger question whether compat should affect attrs, or whether it would be better to completely separate compat from combine_attrs / keep_attrs.

Copy link
Collaborator Author

@keewis keewis Apr 19, 2021

Choose a reason for hiding this comment

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

actually, the result of compat seems to always be to either raise for conflicting attributes ("identical") or to keep the first object's attrs ("override"). Completely separating compat won't be easy because compat="identical" will still raise. Not sure what to do about that – should we deprecate it?

Edit: it seems that conflict is fine, compat="identical" can override any value for combine_attrs

@keewis
Copy link
Collaborator Author

keewis commented Feb 17, 2021

I just noticed this would do the same as #4017, which suggests merging attrs in merge.unique_variables. Would that be the correct place to fix this?

doc/whats-new.rst Outdated Show resolved Hide resolved
@keewis
Copy link
Collaborator Author

keewis commented Apr 5, 2021

I've got a few small questions left (see the comments), but otherwise this should be ready for reviewing

):
"""check that combine_attrs is used on data variables and coords"""
data1 = Dataset(
{"x": ("a", [0], attrs1), "y": ("a", [0], attrs1), "a": ("a", [0], attrs1)}
Copy link
Contributor

Choose a reason for hiding this comment

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

should we also check for Dataset.attrs?

Copy link
Collaborator Author

@keewis keewis Apr 19, 2021

Choose a reason for hiding this comment

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

I had thought we already did that. Turns out we don't, which I didn't realize because that file is in urgent need of a refactor: some test names still reference the removed auto_combine, combine_by_coords and combine_nested are ordered in a way I can't figure out, and I accidentally contributed to the chaos by adding all new tests to TestCombineAuto. Since this seems like a bigger effort I'll try to send in a PR which cleans this up.

doc/whats-new.rst Outdated Show resolved Hide resolved
Copy link
Contributor

@dcherian dcherian left a comment

Choose a reason for hiding this comment

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

Just minor comment.s Thanks @keewis

keewis and others added 4 commits April 20, 2021 00:05
@pep8speaks

This comment has been minimized.

@keewis keewis mentioned this pull request Apr 29, 2021
13 tasks
doc/whats-new.rst Outdated Show resolved Hide resolved
@keewis
Copy link
Collaborator Author

keewis commented May 1, 2021

once the backwards compatibility issue has been resolved this should be ready for merging

doc/whats-new.rst Outdated Show resolved Hide resolved
@keewis
Copy link
Collaborator Author

keewis commented May 5, 2021

once CI passes this should be ready for merging.

@dcherian
Copy link
Contributor

dcherian commented May 5, 2021

Thanks @keewis

@dcherian dcherian merged commit bd4650c into pydata:master May 5, 2021
@keewis keewis deleted the variable-combine_attrs branch May 5, 2021 16:43
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.

4 participants