MCPcopy
hub / github.com/pydata/xarray / compute_chunks

Method compute_chunks

xarray/groupers.py:599–638  ·  view source on GitHub ↗

Compute chunk sizes for this time resampler. This method is used during chunking operations to determine appropriate chunk sizes for the given variable when using this resampler. Parameters ---------- name : Hashable The name of the dime

(self, variable: Variable, *, dim: Hashable)

Source from the content-addressed store, hash-verified

597 )
598
599 def compute_chunks(self, variable: Variable, *, dim: Hashable) -> tuple[int, ...]:
600 """
601 Compute chunk sizes for this time resampler.
602
603 This method is used during chunking operations to determine appropriate
604 chunk sizes for the given variable when using this resampler.
605
606 Parameters
607 ----------
608 name : Hashable
609 The name of the dimension being chunked.
610 variable : Variable
611 The variable being chunked.
612
613 Returns
614 -------
615 tuple[int, ...]
616 A tuple of chunk sizes for the dimension.
617 """
618 if not _contains_datetime_like_objects(variable):
619 raise ValueError(
620 f"Computing chunks with {type(self)!r} only supported for datetime variables. "
621 f"Received variable with dtype {variable.dtype!r} instead."
622 )
623
624 chunks = (
625 DataArray(
626 np.ones(variable.shape, dtype=int),
627 dims=(dim,),
628 coords={dim: variable},
629 )
630 .resample({dim: self})
631 .sum()
632 )
633 # When bins (binning) or time periods are missing (resampling)
634 # we can end up with NaNs. Drop them.
635 if chunks.dtype.kind == "f":
636 chunks = chunks.dropna(dim).astype(int)
637 chunks_tuple: tuple[int, ...] = tuple(chunks.data.tolist())
638 return chunks_tuple
639
640
641def _factorize_given_labels(data: np.ndarray, labels: np.ndarray) -> np.ndarray:

Callers

nothing calls this directly

Calls 7

DataArrayClass · 0.90
typeFunction · 0.85
sumMethod · 0.45
resampleMethod · 0.45
astypeMethod · 0.45
dropnaMethod · 0.45

Tested by

no test coverage detected