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)
| 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 | |
| 641 | def _factorize_given_labels(data: np.ndarray, labels: np.ndarray) -> np.ndarray: |