Skip to content

numpy/mergesort-kind

Pack Severity Fix Versions
NumPy info unsafe, with xpd check --fix --unsafe-fixes All versions

kind="mergesort" is kept only for old code and runs the same stable sort as kind="stable". Write kind="stable".

order = np.argsort(scores, kind="mergesort")
order = np.argsort(scores, kind="stable")

The rule reports kind="mergesort" in np.sort, np.argsort and the sort and argsort methods. The docs keep "mergesort" only for backwards compatibility, and both names select the same stable sort.

Calls through other array libraries, such as jnp.sort and cupy.sort, are left alone.

xpd check --fix --unsafe-fixes applies the fixes of this rule. Check the result, because an unsafe fix can change what the code does.

The safe fix writes kind="stable" in np.sort and np.argsort. The unsafe fix writes the same in a sort or argsort method, because the pattern cannot tell an array from another object.

kind="mergesort" is kept only for backwards compatibility, and it runs the same stable sort as kind="stable". Write kind="stable".

See all rules in the NumPy pack.