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
)
| 654 | |
| 655 | |
| 656 | def 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 | |
| 682 | def season_to_month_tuple(seasons: Sequence[str]) -> tuple[tuple[int, ...], ...]: |
no test coverage detected
searching dependent graphs…