MCPcopy Index your code
hub / github.com/pydata/xarray / __init__

Method __init__

xarray/computation/rolling.py:75–129  ·  view source on GitHub ↗

Moving window object. Parameters ---------- obj : Dataset or DataArray Object to window. windows : mapping of hashable to int A mapping from the name of the dimension to create the rolling window along (e.g. `time`) to the

(
        self,
        obj: T_Xarray,
        windows: Mapping[Any, int],
        min_periods: int | None = None,
        center: bool | Mapping[Any, bool] = False,
    )

Source from the content-addressed store, hash-verified

73 min_periods: int
74
75 def __init__(
76 self,
77 obj: T_Xarray,
78 windows: Mapping[Any, int],
79 min_periods: int | None = None,
80 center: bool | Mapping[Any, bool] = False,
81 ) -> None:
82 """
83 Moving window object.
84
85 Parameters
86 ----------
87 obj : Dataset or DataArray
88 Object to window.
89 windows : mapping of hashable to int
90 A mapping from the name of the dimension to create the rolling
91 window along (e.g. `time`) to the size of the moving window.
92 min_periods : int or None, default: None
93 Minimum number of observations in window required to have a value
94 (otherwise result is NA). The default, None, is equivalent to
95 setting min_periods equal to the size of the window.
96 center : bool or dict-like Hashable to bool, default: False
97 Set the labels at the center of the window. If dict-like, set this
98 property per rolling dimension.
99
100 Returns
101 -------
102 rolling : type of input argument
103 """
104 self.dim = []
105 self.window = []
106 for d, w in windows.items():
107 self.dim.append(d)
108 if w <= 0:
109 raise ValueError("window must be > 0")
110 self.window.append(w)
111
112 self.center = self._mapping_to_list(center, default=False)
113 self.obj = obj
114
115 missing_dims = tuple(dim for dim in self.dim if dim not in self.obj.dims)
116 if missing_dims:
117 # NOTE: we raise KeyError here but ValueError in Coarsen.
118 raise KeyError(
119 f"Window dimensions {missing_dims} not found in {self.obj.__class__.__name__} "
120 f"dimensions {tuple(self.obj.dims)}"
121 )
122
123 # attributes
124 if min_periods is not None and min_periods <= 0:
125 raise ValueError("min_periods must be greater than zero or None")
126
127 self.min_periods = (
128 math.prod(self.window) if min_periods is None else min_periods
129 )
130
131 def __repr__(self) -> str:
132 """provide a nice str repr of our rolling object"""

Callers 2

__init__Method · 0.45
__init__Method · 0.45

Calls 3

_mapping_to_listMethod · 0.95
itemsMethod · 0.80
prodMethod · 0.45

Tested by

no test coverage detected