Closed lakshayg closed 2 years ago
this would be a break with numpy and would introduce yet another convention which, while spelled nicely is incompatible.
so -0 on this.
Makes sense. I have posted an issue on the numpy github repo https://github.com/numpy/numpy/issues/10784. Adding it to pandas should be easy if we can get it into numpy.
@jreback update: numpy (1.15.0) now supports kind='stable'
in the sort function.
does stable map to merge sort?
Yes, it maps to mergesort.
ok would take a PR to do this then (just be an alias - so we have backward compat)
Since numpy supports kind='stable'
, do I need to just update the documentation or should I add something like
if kind == 'stable':
kind = 'mergesort'
at the places where sorting methods are called? cc @jreback
The docs now mention this as supported, but I don't see any test coverage for it. Probably good to add a test that 'stable' is supported (and actually does a stable sort) for sort_values
and sort_index
. Also would good to type the kind
argument using a Literal
with all sorting kind options for consistency everywhere we use them
Looks like we have a sort_kind
fixture that has mergesort
and stable
as well as SortKind
for typing, so I think we can close this.
Code Sample, a copy-pastable example if possible
Problem description
Currently, pandas supports only one way of performing a stable sort i.e. mergesort. Therefore, it makes sense to add an alias for mergesort which will help in making the code more readable.
When I see 'mergesort' written in the code, it is not explicit that this was done to make the sort stable. Therefore having a 'stable' option will fit well with the idea "explicit is better than implicit".
I would like to give this a try if this issue makes sense and the devs decide to accept this proposal.
Output of
pd.show_versions()