Helper function to find unique values with support for python objects. Uses pure python method for object dtype, and numpy method for all other dtypes. Parameters ---------- values : ndarray Values to check for unknowns. return_inverse : bool, default=False
(values, *, return_inverse=False, return_counts=False)
| 12 | |
| 13 | |
| 14 | def _unique(values, *, return_inverse=False, return_counts=False): |
| 15 | """Helper function to find unique values with support for python objects. |
| 16 | |
| 17 | Uses pure python method for object dtype, and numpy method for |
| 18 | all other dtypes. |
| 19 | |
| 20 | Parameters |
| 21 | ---------- |
| 22 | values : ndarray |
| 23 | Values to check for unknowns. |
| 24 | |
| 25 | return_inverse : bool, default=False |
| 26 | If True, also return the indices of the unique values. |
| 27 | |
| 28 | return_counts : bool, default=False |
| 29 | If True, also return the number of times each unique item appears in |
| 30 | values. |
| 31 | |
| 32 | Returns |
| 33 | ------- |
| 34 | unique : ndarray |
| 35 | The sorted unique values. |
| 36 | |
| 37 | unique_inverse : ndarray |
| 38 | The indices to reconstruct the original array from the unique array. |
| 39 | Only provided if `return_inverse` is True. |
| 40 | |
| 41 | unique_counts : ndarray |
| 42 | The number of times each of the unique values comes up in the original |
| 43 | array. Only provided if `return_counts` is True. |
| 44 | """ |
| 45 | if values.dtype == object: |
| 46 | return _unique_python( |
| 47 | values, return_inverse=return_inverse, return_counts=return_counts |
| 48 | ) |
| 49 | # numerical |
| 50 | return _unique_np( |
| 51 | values, return_inverse=return_inverse, return_counts=return_counts |
| 52 | ) |
| 53 | |
| 54 | |
| 55 | def _unique_np(values, return_inverse=False, return_counts=False): |
searching dependent graphs…