dodger487/dplython

Descending sort for arrange

Closed this issue · 3 comments

Currently, arrange only sorts in ascending columns. Functionality should be added so that arrange can sort both ascending and descending. Dplyr syntax uses an additional function, desc, to do this. Additionally, dplyr will sort the data frame based on the resulting values of the "Later". For example,
df %>% arrange(desc(foo))
is essentially equivalent to
df %>% arrange(-foo)

Users can also do stuff like:
df %>% arrange(foo**2) or df %>% arrange(abs(foo))
and it will sort by the largest absolute value of foo.

It'd be nice to have this functionality implemented in dplython as well.

Maybe start by overriding __neg__? I think having -foo mean descending order—even for string and date columns—is nicer than having an additional function like desc.

__neg__ is already overridden, it's just a matter of efficiently sorting by the result of a Later, as opposed to the name of the Later. If we get __neg__ working it should work for free on any expression.

I agree that I'm not a fan of adding in a new function like desc

Descending sort lives! Thanks to pull #33. Closing this for now, should possibly open a new issue to get descending sort to work on string series.