def safe_sort(values, labels=None, na_sentinel=-<NUM_LIT:1>, assume_unique=False):
if not is_list_like(values):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>if not isinstance(values, np.ndarray):<EOL><INDENT>dtype, _ = infer_dtype_from_array(values)<EOL>values = np.asarray(values, dtype=dtype)<EOL><DEDENT>def sort_mixed(values):<EOL><INDENT>str_pos = np.array([isinstance(x, str) for x in values],<EOL>dtype=bool)<EOL>nums = np.sort(values[~str_pos])<EOL>strs = np.sort(values[str_pos])<EOL>return np.concatenate([nums, np.asarray(strs, dtype=object)])<EOL><DEDENT>sorter = None<EOL>if lib.infer_dtype(values, skipna=False) == '<STR_LIT>':<EOL><INDENT>ordered = sort_mixed(values)<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>sorter = values.argsort()<EOL>ordered = values.take(sorter)<EOL><DEDENT>except TypeError:<EOL><INDENT>ordered = sort_mixed(values)<EOL><DEDENT><DEDENT>if labels is None:<EOL><INDENT>return ordered<EOL><DEDENT>if not is_list_like(labels):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>labels = ensure_platform_int(np.asarray(labels))<EOL>from pandas import Index<EOL>if not assume_unique and not Index(values).is_unique:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if sorter is None:<EOL><INDENT>(hash_klass, _), values = algorithms._get_data_algo(<EOL>values, algorithms._hashtables)<EOL>t = hash_klass(len(values))<EOL>t.map_locations(values)<EOL>sorter = ensure_platform_int(t.lookup(ordered))<EOL><DEDENT>reverse_indexer = np.empty(len(sorter), dtype=np.int_)<EOL>reverse_indexer.put(sorter, np.arange(len(sorter)))<EOL>mask = (labels < -len(values)) | (labels >= len(values)) |(labels == na_sentinel)<EOL>new_labels = reverse_indexer.take(labels, mode='<STR_LIT>')<EOL>np.putmask(new_labels, mask, na_sentinel)<EOL>return ordered, ensure_platform_int(new_labels)<EOL>
Sort ``values`` and reorder corresponding ``labels``.
``values`` should be unique if ``labels`` is not None.
Safe for use with mixed types (int, str), orders ints before strs.

.. versionadded:: 0.19.0

Parameters
----------
values : list-like
    Sequence; must be unique if ``labels`` is not None.
labels : list_like
    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 ``labels`` to mark "not found".
    Ignored when ``labels`` is None.
assume_unique : bool, default False
    When True, ``values`` are assumed to be unique, which can speed up
    the calculation. Ignored when ``labels`` is None.

Returns
-------
ordered : ndarray
    Sorted ``values``
new_labels : ndarray
    Reordered ``labels``; returned when ``labels`` is not None.

Raises
------
TypeError
    * If ``values`` is not list-like or if ``labels`` is neither None
    nor list-like
    * If ``values`` cannot be sorted
ValueError
    * If ``labels`` is not None and ``values`` contain duplicates.