pandas 1.4.2

ParametersRaisesReturns
safe_sort(values, codes=None, na_sentinel: 'int' = -1, assume_unique: 'bool' = False, verify: 'bool' = True) -> 'np.ndarray | tuple[np.ndarray, np.ndarray]'

values should be unique if codes is not None. Safe for use with mixed types (int, str), orders ints before strs.

Parameters

values : list-like

Sequence; must be unique if codes is not None.

codes : list_like, optional

Indices to values . All out of bound indices are treated as "not found" and will be masked with na_sentinel .

na_sentinel : int, default -1

Value in codes to mark "not found". Ignored when codes is None.

assume_unique : bool, default False

When True, values are assumed to be unique, which can speed up the calculation. Ignored when codes is None.

verify : bool, default True

Check if codes are out of bound for the values and put out of bound codes equal to na_sentinel. If verify=False , it is assumed there are no out of bound codes. Ignored when codes is None.

versionadded

Raises

TypeError
  • If values is not list-like or if codes is neither None

nor list-like * If values cannot be sorted

ValueError
  • If codes is not None and values contain duplicates.

Returns

ordered : ndarray

Sorted values

new_codes : ndarray

Reordered codes ; returned when codes is not None.

Sort values and reorder corresponding codes .

Examples

See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/algorithms.py#1663
type: <class 'function'>
Commit: