-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add template xarray object kwarg to map_blocks #3816
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
Changes from all commits
064b583
1f14b11
045ae2b
0e37b63
5704e84
2c458e1
dced076
717d900
42a9070
64ba31f
a68cb41
0bc3754
ee66c88
d52dfd6
8ef47f6
376f242
d9029eb
6f69955
da62535
4a355e6
66fe4c4
085ce9a
0f741e2
869e62d
334e8d3
4dd699e
27eb873
04a2c3c
4b92168
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 |
---|---|---|
|
@@ -3260,34 +3260,38 @@ def map_blocks( | |
func: "Callable[..., T_DSorDA]", | ||
args: Sequence[Any] = (), | ||
kwargs: Mapping[str, Any] = None, | ||
template: Union["DataArray", "Dataset"] = None, | ||
) -> "T_DSorDA": | ||
""" | ||
Apply a function to each chunk of this DataArray. This method is experimental | ||
and its signature may change. | ||
Apply a function to each block of this DataArray. | ||
|
||
.. warning:: | ||
This method is experimental and its signature may change. | ||
|
||
Parameters | ||
---------- | ||
func: callable | ||
User-provided function that accepts a DataArray as its first parameter. The | ||
function will receive a subset of this DataArray, corresponding to one chunk | ||
along each chunked dimension. ``func`` will be executed as | ||
``func(obj_subset, *args, **kwargs)``. | ||
|
||
The function will be first run on mocked-up data, that looks like this array | ||
but has sizes 0, to determine properties of the returned object such as | ||
dtype, variable names, new dimensions and new indexes (if any). | ||
User-provided function that accepts a DataArray as its first | ||
parameter. The function will receive a subset, i.e. one block, of this DataArray | ||
(see below), corresponding to one chunk along each chunked dimension. ``func`` will be | ||
executed as ``func(block_subset, *args, **kwargs)``. | ||
|
||
This function must return either a single DataArray or a single Dataset. | ||
|
||
This function cannot change size of existing dimensions, or add new chunked | ||
dimensions. | ||
This function cannot add a new chunked dimension. | ||
args: Sequence | ||
Passed verbatim to func after unpacking, after the sliced DataArray. xarray | ||
objects, if any, will not be split by chunks. Passing dask collections is | ||
not allowed. | ||
kwargs: Mapping | ||
Passed verbatim to func after unpacking. xarray objects, if any, will not be | ||
split by chunks. Passing dask collections is not allowed. | ||
template: (optional) DataArray, Dataset | ||
xarray object representing the final result after compute is called. If not provided, | ||
the function will be first run on mocked-up data, that looks like 'obj' but | ||
has sizes 0, to determine properties of the returned object such as dtype, | ||
variable names, new dimensions and new indexes (if any). | ||
'template' must be provided if the function changes the size of existing dimensions. | ||
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. I assume attrs are also copied from the template and ignored from the computed chunks? 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. Yes. But I don't know that this is right. With auto-inferred templates, attrs are set by the user function. I think it would be nice to preserve that behaviour. What do you think? 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. Thinking about this some more... there's no way to update 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. Correct, |
||
|
||
Returns | ||
------- | ||
|
@@ -3310,7 +3314,7 @@ def map_blocks( | |
""" | ||
from .parallel import map_blocks | ||
|
||
return map_blocks(func, self, args, kwargs) | ||
return map_blocks(func, self, args, kwargs, template) | ||
|
||
def polyfit( | ||
self, | ||
|
Uh oh!
There was an error while loading. Please reload this page.