11import functools
22import warnings
3- from typing import Callable
3+ from typing import Any , Callable , Dict
44
55import numpy as np
66
77from . import dtypes , duck_array_ops , utils
88from .dask_array_ops import dask_rolling_wrapper
9- from .ops import inject_coarsen_methods
9+ from .ops import inject_reduce_methods
1010from .pycompat import dask_array_type
1111
1212try :
@@ -542,6 +542,11 @@ def __init__(self, obj, windows, boundary, side, coord_func):
542542 self .side = side
543543 self .boundary = boundary
544544
545+ absent_dims = [dim for dim in windows .keys () if dim not in self .obj .dims ]
546+ if absent_dims :
547+ raise ValueError (
548+ f"Dimensions { absent_dims !r} not found in { self .obj .__class__ .__name__ } ."
549+ )
545550 if not utils .is_dict_like (coord_func ):
546551 coord_func = {d : coord_func for d in self .obj .dims }
547552 for c in self .obj .coords :
@@ -565,18 +570,23 @@ def __repr__(self):
565570class DataArrayCoarsen (Coarsen ):
566571 __slots__ = ()
567572
573+ _reduce_extra_args_docstring = """"""
574+
568575 @classmethod
569- def _reduce_method (cls , func ):
576+ def _reduce_method (cls , func : Callable , include_skipna : bool , numeric_only : bool ):
570577 """
571- Return a wrapped function for injecting numpy methods.
572- see ops.inject_coarsen_methods
578+ Return a wrapped function for injecting reduction methods.
579+ see ops.inject_reduce_methods
573580 """
581+ kwargs : Dict [str , Any ] = {}
582+ if include_skipna :
583+ kwargs ["skipna" ] = None
574584
575585 def wrapped_func (self , ** kwargs ):
576586 from .dataarray import DataArray
577587
578588 reduced = self .obj .variable .coarsen (
579- self .windows , func , self .boundary , self .side
589+ self .windows , func , self .boundary , self .side , ** kwargs
580590 )
581591 coords = {}
582592 for c , v in self .obj .coords .items ():
@@ -585,7 +595,11 @@ def wrapped_func(self, **kwargs):
585595 else :
586596 if any (d in self .windows for d in v .dims ):
587597 coords [c ] = v .variable .coarsen (
588- self .windows , self .coord_func [c ], self .boundary , self .side
598+ self .windows ,
599+ self .coord_func [c ],
600+ self .boundary ,
601+ self .side ,
602+ ** kwargs ,
589603 )
590604 else :
591605 coords [c ] = v
@@ -597,27 +611,36 @@ def wrapped_func(self, **kwargs):
597611class DatasetCoarsen (Coarsen ):
598612 __slots__ = ()
599613
614+ _reduce_extra_args_docstring = """"""
615+
600616 @classmethod
601- def _reduce_method (cls , func ):
617+ def _reduce_method (cls , func : Callable , include_skipna : bool , numeric_only : bool ):
602618 """
603- Return a wrapped function for injecting numpy methods.
604- see ops.inject_coarsen_methods
619+ Return a wrapped function for injecting reduction methods.
620+ see ops.inject_reduce_methods
605621 """
622+ kwargs : Dict [str , Any ] = {}
623+ if include_skipna :
624+ kwargs ["skipna" ] = None
606625
607626 def wrapped_func (self , ** kwargs ):
608627 from .dataset import Dataset
609628
610629 reduced = {}
611630 for key , da in self .obj .data_vars .items ():
612631 reduced [key ] = da .variable .coarsen (
613- self .windows , func , self .boundary , self .side
632+ self .windows , func , self .boundary , self .side , ** kwargs
614633 )
615634
616635 coords = {}
617636 for c , v in self .obj .coords .items ():
618637 if any (d in self .windows for d in v .dims ):
619638 coords [c ] = v .variable .coarsen (
620- self .windows , self .coord_func [c ], self .boundary , self .side
639+ self .windows ,
640+ self .coord_func [c ],
641+ self .boundary ,
642+ self .side ,
643+ ** kwargs ,
621644 )
622645 else :
623646 coords [c ] = v .variable
@@ -626,5 +649,5 @@ def wrapped_func(self, **kwargs):
626649 return wrapped_func
627650
628651
629- inject_coarsen_methods (DataArrayCoarsen )
630- inject_coarsen_methods (DatasetCoarsen )
652+ inject_reduce_methods (DataArrayCoarsen )
653+ inject_reduce_methods (DatasetCoarsen )
0 commit comments