MCPcopy Index your code
hub / github.com/pydata/xarray / unique_value_groups

Function unique_value_groups

xarray/groupers.py:656–679  ·  view source on GitHub ↗

Group an array by its unique values. Parameters ---------- ar : array-like Input array. This will be flattened if it is not already 1-D. sort : bool, default: True Whether or not to sort unique values. Returns ------- values : np.ndarray Sorted,

(
    ar, sort: bool = True
)

Source from the content-addressed store, hash-verified

654
655
656def unique_value_groups(
657 ar, sort: bool = True
658) -> tuple[np.ndarray | pd.Index, np.ndarray]:
659 """Group an array by its unique values.
660
661 Parameters
662 ----------
663 ar : array-like
664 Input array. This will be flattened if it is not already 1-D.
665 sort : bool, default: True
666 Whether or not to sort unique values.
667
668 Returns
669 -------
670 values : np.ndarray
671 Sorted, unique values as returned by `np.unique`.
672 indices : list of lists of int
673 Each element provides the integer indices in `ar` with values given by
674 the corresponding value in `unique_values`.
675 """
676 inverse, values = pd.factorize(ar, sort=sort)
677 if isinstance(values, pd.MultiIndex):
678 values.names = ar.names
679 return values, inverse
680
681
682def season_to_month_tuple(seasons: Sequence[str]) -> tuple[tuple[int, ...], ...]:

Callers 1

_factorize_uniqueMethod · 0.85

Calls 1

factorizeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…