Wrapper around a Grouper object. The Grouper object represents an abstract instruction to group an object. The ResolvedGrouper object is a concrete version that contains all the common logic necessary for a GroupBy problem including the intermediates necessary for executing a G
| 287 | |
| 288 | @dataclass |
| 289 | class ResolvedGrouper(Generic[T_DataWithCoords]): |
| 290 | """ |
| 291 | Wrapper around a Grouper object. |
| 292 | |
| 293 | The Grouper object represents an abstract instruction to group an object. |
| 294 | The ResolvedGrouper object is a concrete version that contains all the common |
| 295 | logic necessary for a GroupBy problem including the intermediates necessary for |
| 296 | executing a GroupBy calculation. Specialization to the grouping problem at hand, |
| 297 | is accomplished by calling the `factorize` method on the encapsulated Grouper |
| 298 | object. |
| 299 | |
| 300 | This class is private API, while Groupers are public. |
| 301 | """ |
| 302 | |
| 303 | grouper: Grouper |
| 304 | group: T_Group |
| 305 | obj: T_DataWithCoords |
| 306 | eagerly_compute_group: Literal[False] | None = field(repr=False, default=None) |
| 307 | |
| 308 | # returned by factorize: |
| 309 | encoded: EncodedGroups = field(init=False, repr=False) |
| 310 | |
| 311 | @property |
| 312 | def full_index(self) -> pd.Index: |
| 313 | return self.encoded.full_index |
| 314 | |
| 315 | @property |
| 316 | def codes(self) -> DataArray: |
| 317 | return self.encoded.codes |
| 318 | |
| 319 | @property |
| 320 | def unique_coord(self) -> Variable | _DummyGroup: |
| 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( |
no outgoing calls
no test coverage detected
searching dependent graphs…