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

Method factorize

xarray/groupers.py:239–261  ·  view source on GitHub ↗
(self, group: T_Group)

Source from the content-addressed store, hash-verified

237 return type(self)()
238
239 def factorize(self, group: T_Group) -> EncodedGroups:
240 self.group = group
241
242 if is_chunked_array(group.data) and self.labels is None:
243 raise ValueError(
244 "When grouping by a dask array, `labels` must be passed using "
245 "a UniqueGrouper object."
246 )
247 if self.labels is not None:
248 return self._factorize_given_labels(group)
249
250 index = self.group_as_index
251 is_unique_and_monotonic = isinstance(self.group, _DummyGroup) or (
252 index.is_unique
253 and (index.is_monotonic_increasing or index.is_monotonic_decreasing)
254 )
255 is_dimension = self.group.dims == (self.group.name,)
256 can_squeeze = is_dimension and is_unique_and_monotonic
257
258 if can_squeeze:
259 return self._factorize_dummy()
260 else:
261 return self._factorize_unique()
262
263 def _factorize_given_labels(self, group: T_Group) -> EncodedGroups:
264 codes = apply_ufunc(

Callers

nothing calls this directly

Calls 4

_factorize_dummyMethod · 0.95
_factorize_uniqueMethod · 0.95
is_chunked_arrayFunction · 0.90

Tested by

no test coverage detected