-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Add tests to ensure sort preserved by groupby, add docs #10931
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 tests to ensure sort preserved by groupby, add docs #10931
Conversation
ed6eb1a
to
8bcd4a5
Compare
g.get_group('A') | ||
|
||
g.get_group('B') | ||
|
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.
hmm, this is True, but I think the average user will find this a bit confusing. Can you expand/reword a bit. (its an important point), but not sure how to describe it.
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.
Ok -- dropped the discussion of what exactly is happening behind the scenes, tried to clear up the explanation above, and fleshed out the examples a little more. That clearer?
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.
Is there any reason a user would even expect that the already created groupby object would change after sorting the original frame?
Is there an example of confusion? As adding this explanation of something that I would have never thought of seems to make it only more complex than it should be IMO
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.
I agree with Joris. This behavior is entirely consistent with the standard memory model in Python. It does not need explaining.
c77e701
to
f579d6e
Compare
@jreback updated! |
|
||
.. note:: | ||
|
||
Users should be careful about re-sorting their data after execution of ``groupby()``, however. ``groupby()`` ensures that the order of observations within each group will always be the same as they were in the original data at the time that ``groupby()`` was executed. If a user creates a ``groupby()`` object *and then re-sorts the original data*, the order of observations within each group created by ``groupby()`` will reflect the order in which observations were sorted when ``groupby()`` was executed, **not** the order of observations following the re-sorting. For example: |
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.
Can you hard wrap here?
The basic part on sort=True/False and sort preserved within groups looks good! However, I don't really seem to grasp the need to explain the sorting after groupby: "Users should be careful about re-sorting their data after execution of |
b060c0e
to
4817cb3
Compare
@jorisvandenbossche @shoyer @jreback OK, warning dropped! |
Sort group keys. Get better performance by turning this off | ||
Sort group keys. Get better performance by turning this off. | ||
Note this does not influence the order of observations within each group. | ||
groupby preserves the sorted order of the target object |
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.
sorted order -> order ? (as the order within a group is not necessarily sorted?)
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.
what about "order in which observations appear"?
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.
or just order of observations?
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.
or 'rows'?
groupby preserves the order of the rows within each group
4817cb3
to
3b49fad
Compare
@jorisvandenbossche great, added. |
Add tests to ensure sort preserved by groupby, add docs
@nickeubank thanks! |
xref #9651
closes #8588
Adds test to ensure the sort of a target object is preserved within
groupby()
groups, modifies docs to make it clear sort is preserved within groups.