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

Class _DummyGroup

xarray/core/groupby.py:186–251  ·  view source on GitHub ↗

Class for keeping track of grouped dimensions without coordinates. Should not be user visible.

Source from the content-addressed store, hash-verified

184
185
186class _DummyGroup(Generic[T_Xarray]):
187 """Class for keeping track of grouped dimensions without coordinates.
188
189 Should not be user visible.
190 """
191
192 __slots__ = ("coords", "dataarray", "name", "size")
193
194 def __init__(self, obj: T_Xarray, name: Hashable, coords) -> None:
195 self.name = name
196 self.coords = coords
197 self.size = obj.sizes[name]
198
199 @property
200 def dims(self) -> tuple[Hashable]:
201 return (self.name,)
202
203 @property
204 def ndim(self) -> Literal[1]:
205 return 1
206
207 @property
208 def values(self) -> range:
209 return range(self.size)
210
211 @property
212 def data(self) -> np.ndarray:
213 return np.arange(self.size, dtype=int)
214
215 def __array__(
216 self, dtype: np.typing.DTypeLike | None = None, /, *, copy: bool | None = None
217 ) -> np.ndarray:
218 if copy is False:
219 raise NotImplementedError(f"An array copy is necessary, got {copy = }.")
220 return np.arange(self.size)
221
222 @property
223 def shape(self) -> tuple[int, ...]:
224 return (self.size,)
225
226 @property
227 def attrs(self) -> dict:
228 return {}
229
230 def __getitem__(self, key):
231 if isinstance(key, tuple):
232 (key,) = key
233 return self.values[key]
234
235 def to_index(self) -> pd.Index:
236 # could be pd.RangeIndex?
237 return pd.Index(np.arange(self.size))
238
239 def copy(self, deep: bool = True, data: Any = None):
240 raise NotImplementedError
241
242 def to_dataarray(self) -> DataArray:
243 from xarray.core.dataarray import DataArray

Callers 1

_resolve_groupFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…