@@ -187,7 +187,7 @@ def method(self, keep_attrs=None, **kwargs):
187
187
rolling_agg_func = rolling_agg_func ,
188
188
keep_attrs = keep_attrs ,
189
189
fillna = fillna ,
190
- automatic_rechunk = automatic_rechunk ,
190
+ sliding_window_kwargs = dict ( automatic_rechunk = automatic_rechunk ) ,
191
191
** kwargs ,
192
192
)
193
193
@@ -329,7 +329,7 @@ def construct(
329
329
stride : int | Mapping [Any , int ] = 1 ,
330
330
fill_value : Any = dtypes .NA ,
331
331
keep_attrs : bool | None = None ,
332
- automatic_rechunk : bool = True ,
332
+ sliding_window_kwargs : Mapping [ Any , Any ] | None = None ,
333
333
** window_dim_kwargs : Hashable ,
334
334
) -> DataArray :
335
335
"""
@@ -348,10 +348,9 @@ def construct(
348
348
If True, the attributes (``attrs``) will be copied from the original
349
349
object to the new one. If False, the new object will be returned
350
350
without attributes. If None uses the global default.
351
- automatic_rechunk: bool, default True
352
- Whether dask should automatically rechunk the output to avoid
353
- exploding chunk sizes. Importantly, each chunk will be a view of the data
354
- so large chunk sizes are only safe if *no* copies are made later.
351
+ sliding_window_kwargs : Mapping
352
+ Keyword arguments that should be passed to the underlying array type's
353
+ ``sliding_window_view`` function.
355
354
**window_dim_kwargs : Hashable, optional
356
355
The keyword arguments form of ``window_dim`` {dim: new_name, ...}.
357
356
@@ -365,6 +364,15 @@ def construct(
365
364
numpy.lib.stride_tricks.sliding_window_view
366
365
dask.array.lib.stride_tricks.sliding_window_view
367
366
367
+ Notes
368
+ -----
369
+ With dask arrays, it's possible to pass the ``automatic_rechunk`` kwarg as
370
+ ``sliding_window_kwargs={"automatic_rechunk": True}``. This controls
371
+ whether dask should automatically rechunk the output to avoid
372
+ exploding chunk sizes. Automatically rechunking is the default behaviour.
373
+ Importantly, each chunk will be a view of the data so large chunk sizes are
374
+ only safe if *no* copies are made later.
375
+
368
376
Examples
369
377
--------
370
378
>>> da = xr.DataArray(np.arange(8).reshape(2, 4), dims=("a", "b"))
@@ -399,13 +407,15 @@ def construct(
399
407
400
408
"""
401
409
410
+ if sliding_window_kwargs is None :
411
+ sliding_window_kwargs = {}
402
412
return self ._construct (
403
413
self .obj ,
404
414
window_dim = window_dim ,
405
415
stride = stride ,
406
416
fill_value = fill_value ,
407
417
keep_attrs = keep_attrs ,
408
- automatic_rechunk = automatic_rechunk ,
418
+ sliding_window_kwargs = sliding_window_kwargs ,
409
419
** window_dim_kwargs ,
410
420
)
411
421
@@ -417,11 +427,14 @@ def _construct(
417
427
stride : int | Mapping [Any , int ] = 1 ,
418
428
fill_value : Any = dtypes .NA ,
419
429
keep_attrs : bool | None = None ,
420
- automatic_rechunk : bool = True ,
430
+ sliding_window_kwargs : Mapping [ Any , Any ] | None = None ,
421
431
** window_dim_kwargs : Hashable ,
422
432
) -> DataArray :
423
433
from xarray .core .dataarray import DataArray
424
434
435
+ if sliding_window_kwargs is None :
436
+ sliding_window_kwargs = {}
437
+
425
438
keep_attrs = self ._get_keep_attrs (keep_attrs )
426
439
427
440
if window_dim is None :
@@ -442,7 +455,7 @@ def _construct(
442
455
window_dims ,
443
456
center = self .center ,
444
457
fill_value = fill_value ,
445
- automatic_rechunk = automatic_rechunk ,
458
+ ** sliding_window_kwargs ,
446
459
)
447
460
448
461
attrs = obj .attrs if keep_attrs else {}
@@ -463,7 +476,7 @@ def reduce(
463
476
func : Callable ,
464
477
keep_attrs : bool | None = None ,
465
478
* ,
466
- automatic_rechunk : bool = True ,
479
+ sliding_window_kwargs : Mapping [ Any , Any ] | None = None ,
467
480
** kwargs : Any ,
468
481
) -> DataArray :
469
482
"""Reduce each window by applying `func`.
@@ -480,10 +493,9 @@ def reduce(
480
493
If True, the attributes (``attrs``) will be copied from the original
481
494
object to the new one. If False, the new object will be returned
482
495
without attributes. If None uses the global default.
483
- automatic_rechunk: bool, default True
484
- Whether dask should automatically rechunk the output of ``construct`` to avoid
485
- exploding chunk sizes. Importantly, each chunk will be a view of the data
486
- so large chunk sizes are only safe if *no* copies are made in ``func``.
496
+ sliding_window_kwargs
497
+ Keyword arguments that should be passed to the underlying array type's
498
+ ``sliding_window_view`` function.
487
499
**kwargs : dict
488
500
Additional keyword arguments passed on to `func`.
489
501
@@ -492,6 +504,15 @@ def reduce(
492
504
reduced : DataArray
493
505
Array with summarized data.
494
506
507
+ Notes
508
+ -----
509
+ With dask arrays, it's possible to pass the ``automatic_rechunk`` kwarg as
510
+ ``sliding_window_kwargs={"automatic_rechunk": True}``. This controls
511
+ whether dask should automatically rechunk the output to avoid
512
+ exploding chunk sizes. Automatically rechunking is the default behaviour.
513
+ Importantly, each chunk will be a view of the data so large chunk sizes are
514
+ only safe if *no* copies are made later.
515
+
495
516
Examples
496
517
--------
497
518
>>> da = xr.DataArray(np.arange(8).reshape(2, 4), dims=("a", "b"))
@@ -541,7 +562,7 @@ def reduce(
541
562
window_dim = rolling_dim ,
542
563
keep_attrs = keep_attrs ,
543
564
fill_value = fillna ,
544
- automatic_rechunk = automatic_rechunk ,
565
+ sliding_window_kwargs = sliding_window_kwargs ,
545
566
)
546
567
547
568
dim = list (rolling_dim .values ())
@@ -873,7 +894,7 @@ def construct(
873
894
stride : int | Mapping [Any , int ] = 1 ,
874
895
fill_value : Any = dtypes .NA ,
875
896
keep_attrs : bool | None = None ,
876
- automatic_rechunk : bool = True ,
897
+ sliding_window_kwargs : Mapping [ Any , Any ] | None = None ,
877
898
** window_dim_kwargs : Hashable ,
878
899
) -> Dataset :
879
900
"""
@@ -889,10 +910,9 @@ def construct(
889
910
size of stride for the rolling window.
890
911
fill_value : Any, default: dtypes.NA
891
912
Filling value to match the dimension size.
892
- automatic_rechunk: bool, default True
893
- Whether dask should automatically rechunk the output to avoid
894
- exploding chunk sizes. Importantly, each chunk will be a view of the data
895
- so large chunk sizes are only safe if *no* copies are made later.
913
+ sliding_window_kwargs
914
+ Keyword arguments that should be passed to the underlying array type's
915
+ ``sliding_window_view`` function.
896
916
**window_dim_kwargs : {dim: new_name, ...}, optional
897
917
The keyword arguments form of ``window_dim``.
898
918
@@ -904,6 +924,15 @@ def construct(
904
924
--------
905
925
numpy.lib.stride_tricks.sliding_window_view
906
926
dask.array.lib.stride_tricks.sliding_window_view
927
+
928
+ Notes
929
+ -----
930
+ With dask arrays, it's possible to pass the ``automatic_rechunk`` kwarg as
931
+ ``sliding_window_kwargs={"automatic_rechunk": True}``. This controls
932
+ whether dask should automatically rechunk the output to avoid
933
+ exploding chunk sizes. Automatically rechunking is the default behaviour.
934
+ Importantly, each chunk will be a view of the data so large chunk sizes are
935
+ only safe if *no* copies are made later.
907
936
"""
908
937
909
938
from xarray .core .dataset import Dataset
@@ -935,6 +964,7 @@ def construct(
935
964
fill_value = fill_value ,
936
965
stride = st ,
937
966
keep_attrs = keep_attrs ,
967
+ sliding_window_kwargs = sliding_window_kwargs ,
938
968
)
939
969
else :
940
970
dataset [key ] = da .copy ()
0 commit comments