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

Method _factorize_unique

xarray/groupers.py:282–305  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

280 )
281
282 def _factorize_unique(self) -> EncodedGroups:
283 # look through group to find the unique values
284 sort = not isinstance(self.group_as_index, pd.MultiIndex)
285 unique_values, codes_ = unique_value_groups(self.group_as_index, sort=sort)
286 if array_all(codes_ == -1):
287 raise ValueError(
288 "Failed to group data. Are you grouping by a variable that is all NaN?"
289 )
290 codes = self.group.copy(data=codes_.reshape(self.group.shape), deep=False)
291 unique_coord = Variable(
292 dims=codes.name, data=unique_values, attrs=self.group.attrs
293 )
294 full_index = (
295 unique_values
296 if isinstance(unique_values, pd.MultiIndex)
297 else pd.Index(unique_values)
298 )
299
300 return EncodedGroups(
301 codes=codes,
302 full_index=full_index,
303 unique_coord=unique_coord,
304 coords=coordinates_from_variable(unique_coord),
305 )
306
307 def _factorize_dummy(self) -> EncodedGroups:
308 size = self.group.size

Callers 1

factorizeMethod · 0.95

Calls 6

array_allFunction · 0.90
VariableClass · 0.90
unique_value_groupsFunction · 0.85
EncodedGroupsClass · 0.85
copyMethod · 0.45

Tested by

no test coverage detected