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

Method __post_init__

xarray/core/groupby.py:323–368  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

321 return self.encoded.unique_coord
322
323 def __post_init__(self) -> None:
324 # This copy allows the BinGrouper.factorize() method
325 # to update BinGrouper.bins when provided as int, using the output
326 # of pd.cut
327 # We do not want to modify the original object, since the same grouper
328 # might be used multiple times.
329 from xarray.groupers import BinGrouper, UniqueGrouper
330
331 self.grouper = copy.deepcopy(self.grouper)
332
333 self.group = _resolve_group(self.obj, self.group)
334
335 if self.eagerly_compute_group:
336 raise ValueError(
337 f""""Eagerly computing the DataArray you're grouping by ({self.group.name!r}) "
338 has been removed.
339 Please load this array's data manually using `.compute` or `.load`.
340 To intentionally avoid eager loading, either (1) specify
341 `.groupby({self.group.name}=UniqueGrouper(labels=...))`
342 or (2) pass explicit bin edges using ``bins`` or
343 `.groupby({self.group.name}=BinGrouper(bins=...))`; as appropriate."""
344 )
345 if self.eagerly_compute_group is not None:
346 emit_user_level_warning(
347 "Passing `eagerly_compute_group` is now deprecated. It has no effect.",
348 FutureWarning,
349 )
350
351 if not isinstance(self.group, _DummyGroup) and is_chunked_array(
352 self.group.variable._data
353 ):
354 # This requires a pass to discover the groups present
355 if isinstance(self.grouper, UniqueGrouper) and self.grouper.labels is None:
356 raise ValueError(
357 "Please pass `labels` to UniqueGrouper when grouping by a chunked array."
358 )
359 # this requires a pass to compute the bin edges
360 if isinstance(self.grouper, BinGrouper) and isinstance(
361 self.grouper.bins, int
362 ):
363 raise ValueError(
364 "Please pass explicit bin edges to BinGrouper using the ``bins`` kwarg"
365 "when grouping by a chunked array."
366 )
367
368 self.encoded = self.grouper.factorize(self.group)
369
370 @property
371 def name(self) -> Hashable:

Callers

nothing calls this directly

Calls 4

emit_user_level_warningFunction · 0.90
is_chunked_arrayFunction · 0.90
_resolve_groupFunction · 0.85
factorizeMethod · 0.45

Tested by

no test coverage detected