Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

create the context objects passed to custom combine_attrs functions - #5668

#5668
Open
keewis wants to merge 5 commits into
pydata:mainpydata/xarray:mainfrom
keewis:attrs_contextkeewis/xarray:attrs_contextCopy head branch name to clipboard
Open

create the context objects passed to custom combine_attrs functions#5668
keewis wants to merge 5 commits into
pydata:mainpydata/xarray:mainfrom
keewis:attrs_contextkeewis/xarray:attrs_contextCopy head branch name to clipboard

Conversation

@keewis

@keewis keewis commented Aug 3, 2021

Copy link
Copy Markdown
Collaborator

Follow-up to #4896: this creates the context object in reduce methods and passes it to merge_attrs, with more planned.

Note that for now this is a bit inconvenient to use for provenance tracking (as discussed in the cf-xarray issue) because functions implementing that would still have to deal with merging the attrs.

@github-actions

github-actions Bot commented Aug 3, 2021

Copy link
Copy Markdown
Contributor

Unit Test Results

         6 files           6 suites   51m 18s ⏱️
16 200 tests 14 465 ✔️ 1 735 💤 0 ❌
90 396 runs  82 221 ✔️ 8 175 💤 0 ❌

Results for commit 8d23032.

♻️ This comment has been updated with latest results.

Comment thread xarray/core/variable.py
Comment on lines +1788 to +1789
if isinstance(keep_attrs, bool):
keep_attrs = "override" if keep_attrs else "drop"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can this go in _get_keep_attrs?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

no, because we need to support both of these:

Suggested change
if isinstance(keep_attrs, bool):
keep_attrs = "override" if keep_attrs else "drop"
with xr.set_options(keep_attrs=True):
ds.mean()
ds.mean(keep_attrs=True)

but I can move it to merge_attrs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

merge_attrs would be a good solution.

We could update _get_keep_attrs to _get_keep_attrs(keep_attrs, default=False) and put all the logic in one place but that's a much bigger change.

Comment thread xarray/core/merge.py
@@ -63,6 +63,9 @@ class Context:
def __init__(self, func):
self.func = func

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@keewis do you have an idea of what to do for groupby.mean and similar calls?

@keewis keewis Aug 4, 2021

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

it should be possible to pass the actual (bound?) function (e.g. ds.groupby(...).mean) instead, which would also allow accessing additional data in the combine_attrs function. Not sure how to get a nice repr for that but I guess that's a minor issue.

Edit: to avoid introspecting stack frames, I guess we could pass getattr(self, "name") (where that makes sense)

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.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.