-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: sorted() methods on everything #9816
Comments
see #8239 for much of the same discussion this would actually be a nice soln as changing the existing behavior or order/sort is back incompatible pull requested are welcome! |
Thanks for the vote of interest — I will look for the Pandas team at the PyCon sprints :) |
awesome! this would be amazing to do then! |
Agreed, this is a nice solution! 👍 |
sorted()
methods on everything
From me a 👍 as well! But, I think there are some other aspects of the interface that needs discussion (as seen in #8239): how to specify to sort on a certain column, or column/index combination, default of sorting on index or values, ... |
Is there a reason that we can't just add an |
order is actually an odd term (from R I believe) and sort/sorted is more pythonic the intention would be to replicate sort for DataFrame and order for Series |
…andas-dev#8239 DEPR: remove of na_last from Series.order/Series.sort, xref pandas-dev#5231
It would make Pandas easier to teach, easier to learn, and easier to use if the sorting behavior were the same between series and dataframes. But the existing
order()
andsort()
methods are locked into their old behaviors by all of the code that already depends on them.But a new
sorted()
method could bring symmetry between series and dataframes for code written from now on:Having this new pair of methods with identical conventions, where possible, would solve several different problems that learners have with Pandas today:
Series.sort()
is a special case.sort()
method traditionally returnsNone
and does an in-place sort, but learners have to discover thatDataFrame.sort()
violates this convention in order to match the behavior of the rest of Pandas.Series.order()
which is very difficult to discover, as nothing else in the Python ecosystem is namedorder()
, and since one would normally expect anorder()
method to tell you the order (ascending? descending? none?) instead of imposing a new order.sorted()
, per the universally loved Python built-in, but learners cannot transfer this knowledge to Pandas, where that concept exists but under the two different namesSeries.order()
andDataFrame.sort()
.Yes, the
ed
at the end ofsorted()
would be one character longer thanorder()
and two characters longer than the current practice ofdf.sort()
. But, on balance, I think that most programmers would happily cede two characters in order to be able to use the same method name when they are flipping code between handling series and handling dataframes, and happy to have the option of using the standard Python name for the concept of a non-in-place sort.I suspect that deprecating the old names would be overly disruptive at this point, and they could probably live alongside the new
sorted()
methods without much trouble — new documentation could adopt the new, consistent terminology where possible, if the Pandas developers did not want to disrupt current users of the old inconsistent names.The text was updated successfully, but these errors were encountered: