1
+ from __future__ import annotations
2
+
1
3
from distutils .version import LooseVersion
2
- from typing import TYPE_CHECKING , Generic , Hashable , Mapping , TypeVar , Union
4
+ from typing import Generic , Hashable , Mapping , Union
3
5
4
6
import numpy as np
5
7
6
8
from .options import _get_keep_attrs
7
9
from .pdcompat import count_not_none
8
10
from .pycompat import is_duck_dask_array
9
-
10
- if TYPE_CHECKING :
11
- from .dataarray import DataArray # noqa: F401
12
- from .dataset import Dataset # noqa: F401
13
-
14
- T_DSorDA = TypeVar ("T_DSorDA" , "DataArray" , "Dataset" )
11
+ from .types import T_Xarray
15
12
16
13
17
14
def _get_alpha (com = None , span = None , halflife = None , alpha = None ):
@@ -79,7 +76,7 @@ def _get_center_of_mass(comass, span, halflife, alpha):
79
76
return float (comass )
80
77
81
78
82
- class RollingExp (Generic [T_DSorDA ]):
79
+ class RollingExp (Generic [T_Xarray ]):
83
80
"""
84
81
Exponentially-weighted moving window object.
85
82
Similar to EWM in pandas
@@ -103,16 +100,16 @@ class RollingExp(Generic[T_DSorDA]):
103
100
104
101
def __init__ (
105
102
self ,
106
- obj : T_DSorDA ,
103
+ obj : T_Xarray ,
107
104
windows : Mapping [Hashable , Union [int , float ]],
108
105
window_type : str = "span" ,
109
106
):
110
- self .obj : T_DSorDA = obj
107
+ self .obj : T_Xarray = obj
111
108
dim , window = next (iter (windows .items ()))
112
109
self .dim = dim
113
110
self .alpha = _get_alpha (** {window_type : window })
114
111
115
- def mean (self , keep_attrs : bool = None ) -> T_DSorDA :
112
+ def mean (self , keep_attrs : bool = None ) -> T_Xarray :
116
113
"""
117
114
Exponentially weighted moving average.
118
115
@@ -139,7 +136,7 @@ def mean(self, keep_attrs: bool = None) -> T_DSorDA:
139
136
move_exp_nanmean , dim = self .dim , alpha = self .alpha , keep_attrs = keep_attrs
140
137
)
141
138
142
- def sum (self , keep_attrs : bool = None ) -> T_DSorDA :
139
+ def sum (self , keep_attrs : bool = None ) -> T_Xarray :
143
140
"""
144
141
Exponentially weighted moving sum.
145
142
0 commit comments