-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Groupby filter maintains ordering, closes #4621 #5222
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
BUG: Groupby filter maintains ordering, closes #4621 #5222
Conversation
looks good |
can u add a release notes entry as well |
I'll add the sort keyword. Does that qualify as an API change, or is it too minor? |
pretty minor - just make sure doc string is good |
Ready (assuming Travis agrees!) |
This looks good, though I dislike the use of |
Yes, I agree - that's very confusing. Is the alternative not sorting it? |
sort is the kw in groupby already so it's consistent (or maybe it's sorted?) |
@jreback that's a good point, I'd not seen or used that.
Although this is somewhat different, in that case it is actually sorting the keys. Here we are putting them back into their previous order of the index (and this may - or may not - be sorted)... |
Exactly. IMO, there is a strong case for not even allowing the option to skip the sorting. For one thing, it's difficult to test, which seems like a red flag. (My original tests sorted the result before comparing to the expected one.) |
this is the indexer it should always be sorted it should always be in the same order as the groups which is why it needs sorting, because the groups are sorted (groupsort_indexer) |
Removed sort, including docstring and release notes. Ready. |
BUG: Groupby filter maintains ordering, closes #4621
Simply adds
np.sort
.Includes tests for SeriesGroupBy and DataFrameGroupBy, using indexes that are sequentially increasing, sequentially decreasing, and shuffled. Also, this PR removes all ad hoc sorting involved in the original filter tests -- now no longer needed. Much better!