|
13 | 13 |
|
14 | 14 | import numpy as np
|
15 | 15 | import pandas as pd
|
| 16 | +from numpy.typing import ArrayLike |
16 | 17 |
|
17 | 18 | from xarray.coding.cftime_offsets import BaseCFTimeOffset, _new_to_legacy_freq
|
18 | 19 | from xarray.core import duck_array_ops
|
@@ -99,12 +100,18 @@ def __init__(
|
99 | 100 | assert isinstance(full_index, pd.Index)
|
100 | 101 | self.full_index = full_index
|
101 | 102 |
|
102 |
| - if group_indices is None and not is_chunked_array(codes.data): |
103 |
| - self.group_indices = tuple( |
104 |
| - g |
105 |
| - for g in _codes_to_group_indices(codes.data.ravel(), len(full_index)) |
106 |
| - if g |
107 |
| - ) |
| 103 | + if group_indices is None: |
| 104 | + if not is_chunked_array(codes.data): |
| 105 | + self.group_indices = tuple( |
| 106 | + g |
| 107 | + for g in _codes_to_group_indices( |
| 108 | + codes.data.ravel(), len(full_index) |
| 109 | + ) |
| 110 | + if g |
| 111 | + ) |
| 112 | + else: |
| 113 | + # We will not use this when grouping by a chunked array |
| 114 | + self.group_indices = tuple() |
108 | 115 | else:
|
109 | 116 | self.group_indices = group_indices
|
110 | 117 |
|
@@ -168,13 +175,11 @@ class UniqueGrouper(Grouper):
|
168 | 175 | """
|
169 | 176 |
|
170 | 177 | _group_as_index: pd.Index | None = field(default=None, repr=False)
|
171 |
| - labels: np.ndarray | None = field(default=None) |
| 178 | + labels: ArrayLike | None = field(default=None) |
172 | 179 |
|
173 | 180 | @property
|
174 | 181 | def group_as_index(self) -> pd.Index:
|
175 | 182 | """Caches the group DataArray as a pandas Index."""
|
176 |
| - if is_chunked_array(self.group): |
177 |
| - raise ValueError("Please call compute manually.") |
178 | 183 | if self._group_as_index is None:
|
179 | 184 | if self.group.ndim == 1:
|
180 | 185 | self._group_as_index = self.group.to_index()
|
@@ -214,7 +219,7 @@ def _factorize_given_labels(self, group: T_Group) -> EncodedGroups:
|
214 | 219 | )
|
215 | 220 | return EncodedGroups(
|
216 | 221 | codes=codes,
|
217 |
| - full_index=pd.Index(self.labels), |
| 222 | + full_index=pd.Index(self.labels), # type: ignore[arg-type] |
218 | 223 | unique_coord=Variable(
|
219 | 224 | dims=codes.name,
|
220 | 225 | data=self.labels,
|
@@ -332,7 +337,7 @@ def __post_init__(self) -> None:
|
332 | 337 | raise ValueError("All bin edges are NaN.")
|
333 | 338 |
|
334 | 339 | def _cut(self, data):
|
335 |
| - return pd.cut( # type: ignore [call-overload] |
| 340 | + return pd.cut( |
336 | 341 | np.asarray(data).ravel(),
|
337 | 342 | bins=self.bins,
|
338 | 343 | right=self.right,
|
|
0 commit comments