-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
create the context objects passed to custom combine_attrs
functions
#5668
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
base: main
Are you sure you want to change the base?
Changes from all commits
14ed862
7d3e333
8fedd84
8d23032
ccbcfd2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1818,6 +1818,8 @@ def reduce( | |||||||||||
Array with summarized data and the indicated dimension(s) | ||||||||||||
removed. | ||||||||||||
""" | ||||||||||||
from .merge import Context, merge_attrs | ||||||||||||
|
||||||||||||
if dim == ...: | ||||||||||||
dim = None | ||||||||||||
if dim is not None and axis is not None: | ||||||||||||
|
@@ -1860,7 +1862,13 @@ def reduce( | |||||||||||
|
||||||||||||
if keep_attrs is None: | ||||||||||||
keep_attrs = _get_keep_attrs(default=False) | ||||||||||||
attrs = self._attrs if keep_attrs else None | ||||||||||||
|
||||||||||||
if isinstance(keep_attrs, bool): | ||||||||||||
keep_attrs = "override" if keep_attrs else "drop" | ||||||||||||
Comment on lines
+1866
to
+1867
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can this go in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, because we need to support both of these:
Suggested change
but I can move it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We could update |
||||||||||||
|
||||||||||||
attrs = merge_attrs( | ||||||||||||
[self.attrs], combine_attrs=keep_attrs, context=Context(func.__name__) | ||||||||||||
) | ||||||||||||
|
||||||||||||
return Variable(dims, data, attrs=attrs) | ||||||||||||
|
||||||||||||
|
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.
@keewis do you have an idea of what to do for
groupby.mean
and similar calls?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.
it should be possible to pass the actual (bound?) function (e.g.
ds.groupby(...).mean
) instead, which would also allow accessing additional data in thecombine_attrs
function. Not sure how to get a nicerepr
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)