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.

  • follow-up to #4827, closes #4017
  • Tests added
  • Passes pre-commit run --all-files
  • User visible changes (including notable bug fixes) are documented in whats-new.rst
@keewis
Copy link
Collaborator Author

@keewis 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")

This comment has been minimized.

@keewis

keewis Feb 13, 2021
Author Collaborator

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?)

This comment has been minimized.

@dcherian

dcherian Apr 5, 2021
Contributor

is the old default "override"?

This comment has been minimized.

@keewis

keewis Apr 19, 2021
Author Collaborator

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.

This comment has been minimized.

@keewis

keewis Apr 19, 2021
Author Collaborator

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 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 keewis mentioned this pull request Feb 27, 2021
3 tasks done
@keewis
Copy link
Collaborator Author

@keewis 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)}

This comment has been minimized.

@dcherian

dcherian Apr 5, 2021
Contributor

should we also check for Dataset.attrs?

This comment has been minimized.

@keewis

keewis Apr 19, 2021
Author Collaborator

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

Just minor comment.s Thanks @keewis

keewis and others added 4 commits Apr 19, 2021
@shoyer
shoyer approved these changes Apr 21, 2021
@pep8speaks

This comment has been hidden.

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

@keewis 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 keewis commented May 5, 2021

once CI passes this should be ready for merging.

@dcherian
Copy link
Contributor

@dcherian dcherian commented May 5, 2021

Thanks @keewis

@dcherian dcherian merged commit bd4650c into pydata:master May 5, 2021
12 checks passed
12 checks passed
@github-actions
detect ci trigger
Details
@github-actions
detect ci trigger
Details
@github-actions
detect upstream-dev ci trigger
Details
@github-actions
pre-commit hooks
Details
@github-actions
${{ matrix.os }} py${{ matrix.python-version }}
Details
@github-actions
upstream-dev
Details
@github-actions
Doctests Doctests
Details
@github-actions
${{ matrix.os }} ${{ matrix.env }}
Details
@github-actions
report
Details
@github-actions
Type checking (mypy)
Details
@github-actions
Minimum Version Policy
Details
docs/readthedocs.org:xray Read the Docs build succeeded!
Details
@keewis keewis deleted the keewis:variable-combine_attrs branch May 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants