-
Notifications
You must be signed in to change notification settings - Fork 125
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
Add Series.sort_by
and Series.sort_with
#762
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
For the name, I don't have a strong opinion about it. I think it would be nice to keep the sort
naming, since it seems more clear in the context of the series (and matches Enum
, as you said in the issue). But again, I'm fine with the arrange
naming :)
For the API, I think the version you did here seems better. I would change the arrange
from the DF to follow the same API.
@philss Thanks for looking!
Agreed. But can we without a breaking change? Today way support: s = Explorer.Series.from_list([2, 1, 3])
Explorer.Series.sort(s, direction: :asc) If we want to also support: Explorer.Series.sort(s, remainder(_, 3)) There would be a conflict for the |
We could also do (Or the cursed |
Yeah, I see :/
It's actually a good idea IMHO :D |
I like sort_by a lot and had the same idea. Which means we should pass direction as option for symmetry with I am not ecstatic about sort_with. We could just allow a function in |
I agree -- I like sort_by. Generally I'm keen to use sort consistently with DFs as well and rename arrange -> sort. |
But would we make them all consistent? Arrange? Mutate? To be honest, I dislike mutate, but it would be a huge departure for the library. I think rooting in R or Pandas make sense, and the general agreement is that R wins API-elegance wise. |
I still think mutate doesn't really apply to series so there's nothing to make consistent there. What else would you call it? 100% R wins elegance-wise but it's not necessarily in the names -- in fact, R has a lot of 'creative' naming to avoid namespace conflicts with base. The elegance comes from matching 'verbs' to (tidy data) principles and maintaining parsimony. Which I think we're doing well! I'm pretty sure arrange is one of the cases of avoiding namespace conflict in R. |
For me a mutate could be a map, transform, or anything else that does not imply an in-memory change, but it is not a hill I would die on. if we are renaming arrange, would we call it sort or sort_by? |
Yeah no I totally agree. But mutate in R has always been a bit weird. It's specifically about changing a data frame in some way. Adding, replacing, or changing columns. I'd just call it sort. I'm totally cool with unifying on arrange for both too. I mainly think they should be consistent. I just don't want to skip out on the more obvious |
So maybe sort_by and sort_with for full symmetry with series? |
Although in one we do asc:/desc: and the other does direction: :asc/:desc, so they wouldn’t quite mirror. |
I'm cool with this.
True but I think close enough. :) |
Update:
I've also found some mild inconsistencies in the sorting API (like |
Series.arrange
and Series.arrange_with
Series.sort_by
and Series.sort_with
Yeah, I think there are two issues next: making sure the options are consistent and then renaming DF.arrange. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nits and ship it!
Co-authored-by: José Valim <[email protected]>
Co-authored-by: José Valim <[email protected]>
Adds:
Series.arrange
(macro)Series.arrange_with
(function)Closes:
_
macros inSeries
#730I'm opening this up early. There are two decisions we need to make before I write docs:
Series.arrange{_with}
Series.sort{_with}
(already taken)Series.arrange(s, _, direction: :asc)
(matchesSeries.sort
)Series.arrange(s, asc: _)
(matchesDataFrame.arrange
)