-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Document that Coarsen accepts coord func as callable #7981
base: main
Are you sure you want to change the base?
Conversation
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.
That's a nice improvement, thanks!
I have run into problems regarding this in the past :)
boundary: CoarsenBoundaryOptions = "exact", | ||
side: SideOptions | Mapping[Any, SideOptions] = "left", | ||
keep_attrs=None, | ||
**kwargs, | ||
): |
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.
While at it you could add a return type.
A mapping from the name of the dimension to create the coarsened block along (e.g. `time`) to the size of | ||
the coarsened block. | ||
func : function or str name of function | ||
Function to use to reduce the values of one block down along one or more axes. |
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.
Maybe mention the signature of the function.
I myself have already run into the problem if not knowing what exactly you have to supply.
Also, I never know from which "pool" you can choose the str names, maybe this can be documented better? (Same for the other docstrings)
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.
Also, I never know from which "pool" you can choose the str names, maybe this can be documented better? (Same for the other docstrings)
Yeah this seems like an issue. It's currently literally just any function in the internal duck_array_ops
module, which (a) is hacky AF, (b) is not documented or even very easy to document, and (c) could fail (there are fn's in duck_array_ops
that aren't reductions, for example). I'm not aware of anywhere else in xarray's codebase where we just implicitly allow attempting to get any function from duck_array_ops
like this.
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.
Maybe we could add a public variable in the duck_arr_ops module that collects valid reduction names and add a reference to it?
If 'exact', a ValueError will be raised if dimension size is not a | ||
multiple of window size. If 'trim', the excess indexes are trimmed. | ||
If 'pad', NA will be padded. | ||
side : 'left' or 'right' or mapping from dimension to 'left' or 'right' |
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.
Add **kwargs
as being passed to func.
windows : mapping of hashable to int | ||
A mapping from the name of the dimension to create the coarsened block along (e.g. `time`) to the size of | ||
the coarsened block. | ||
func : function or str name of function |
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.
func : function or str name of function | |
func : Callable or str name of function |
boundary : {"exact", "trim", "pad"} | ||
If 'exact', a ValueError will be raised if dimension size is not a | ||
multiple of window size. If 'trim', the excess indexes are trimmed. | ||
If 'pad', NA will be padded. | ||
side : 'left' or 'right' or mapping from dimension to 'left' or 'right' | ||
coord_func : function (name) or mapping from coordinate name to function (name). | ||
coord_func : function, str name of function, or mapping from coordinate name to function or str name of func. |
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.
coord_func : function, str name of function, or mapping from coordinate name to function or str name of func. | |
coord_func : Callable, str name of function, or mapping from coordinate name to Callable or str name of func. |
Also probably more readable that way because you don't have 4 times "function" in one sentence.
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.
I think we should add an explicit list of function names
self, windows, func, boundary="exact", side="left", keep_attrs=None, **kwargs | ||
self, | ||
windows: Mapping[Any, int], | ||
func: str | Callable, |
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.
func: str | Callable, | |
func: Literal["max", "min", ...] | Callable, |
Documents a hidden feature I noticed yesterday, corrects incorrect docstrings, and tidies up some of the typing internally.
Closes #xxxxwhats-new.rst
New functions/methods are listed inapi.rst