-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
DOC: Improving docstring of take method #16948
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2063,7 +2063,8 @@ def __delitem__(self, key): | |
|
||
def take(self, indices, axis=0, convert=True, is_copy=True, **kwargs): | ||
""" | ||
Analogous to ndarray.take | ||
Return an object formed from the elements in the given indices along an | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We generally try to fit this description on one line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
axis | ||
|
||
Parameters | ||
---------- | ||
|
@@ -2072,6 +2073,44 @@ def take(self, indices, axis=0, convert=True, is_copy=True, **kwargs): | |
convert : translate neg to pos indices (default) | ||
is_copy : mark the returned frame as a copy | ||
|
||
Examples | ||
-------- | ||
>>> import numpy as np | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you don't need the imports here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
>>> import pandas as pd | ||
>>> df = pd.DataFrame([('falcon', 'bird', 389.0), | ||
('parrot', 'bird', 24.0), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. give this an index (like [0, 3, 2, 1]) or something to emphasize that these are positional operations There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
('lion', 'mammal', 80.5), | ||
('monkey', 'mammal', np.nan)], | ||
columns=('name', 'class', 'max_speed')) | ||
>>> df | ||
name class max_speed | ||
0 falcon bird 389.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a comment that these are positional selections (where you think it is needed) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
1 parrot bird 24.0 | ||
2 lion mammal 80.5 | ||
3 monkey mammal NaN | ||
|
||
Take elements at indices 0 and 3 along the axis 0 (default) | ||
|
||
>>> df.take([0, 3]) | ||
0 falcon bird 389.0 | ||
3 monkey mammal NaN | ||
|
||
Take elements at indices 1 and 2 along the axis 1 | ||
|
||
>>> df.take([1, 2], axis=1) | ||
class max_speed | ||
0 bird 389.0 | ||
1 bird 24.0 | ||
2 mammal 80.5 | ||
3 mammal NaN | ||
|
||
Also, we may take elements using negative integers for pos indices | ||
|
||
>>> df.take([-1, -2]) | ||
name class max_speed | ||
3 monkey mammal NaN | ||
2 lion mammal 80.5 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is a bit unfortunate in the example that it is exactly indices [1, 2] for [-1, -2], so maybe change the indices a bit so they don't match? (also because you said "We may take elements using negative integers for positive indices.", which can be interpreted that negative values are interpreted as the positive index of that value) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
Returns | ||
------- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a See Also, showing ndarray.take There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
taken : type of caller | ||
|
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.
add that this is a positional selection.
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.
Done.