-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
DOC: Improving docstring of take method #16948
Conversation
Hello @matagus! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on August 21, 2017 at 08:25 Hours UTC |
pandas/core/generic.py
Outdated
@@ -1939,7 +1939,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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
pandas/core/generic.py
Outdated
@@ -1948,6 +1949,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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
pandas/core/generic.py
Outdated
@@ -1939,7 +1939,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 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.
pandas/core/generic.py
Outdated
name class max_speed | ||
3 monkey mammal NaN | ||
2 lion mammal 80.5 | ||
|
||
Returns | ||
------- |
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 a See Also, showing ndarray.take
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.
pandas/core/generic.py
Outdated
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
pandas/core/generic.py
Outdated
>>> import numpy as np | ||
>>> 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Codecov Report
@@ Coverage Diff @@
## master #16948 +/- ##
=========================================
Coverage ? 91.01%
=========================================
Files ? 162
Lines ? 49567
Branches ? 0
=========================================
Hits ? 45114
Misses ? 4453
Partials ? 0
Continue to review full report at Codecov.
|
can you update |
@matagus Do you have time to update this according to the feedback? |
@gfyoung if you have a chance can you fix up. |
595cee8
to
9fb4aa4
Compare
@jreback : Changes requested have been addressed. PTAL. |
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.
Looks good! Some nitpicks
pandas/core/generic.py
Outdated
2 mammal 80.5 | ||
1 mammal NaN | ||
|
||
We may take elements using negative integers for positive indices. |
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 clarify that this is for starting at the end?
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.
pandas/core/generic.py
Outdated
>>> df.take([-1, -2]) | ||
name class max_speed | ||
1 monkey mammal NaN | ||
2 lion mammal 80.5 |
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
pandas/core/generic.py
Outdated
|
||
See Also | ||
-------- | ||
ndarray.take |
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.
Does this need numpy.
before it? (not sure, but for clarity maybe does no harm in any case)
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.
pandas/core/generic.py
Outdated
|
||
This means that we are not indexing according to actual values in | ||
the index attribute of the object. We are indexing according to the | ||
actual position of the element in the object's array of values. |
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 would just write "actual position of the elements in the object"
("object's array of values" can possibly cause some confusion I think)
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.
e8f7bc3
to
0a07775
Compare
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.
Perfect!
@jorisvandenbossche : Absolutely. Good to know. On a separate note, what is the purpose of the >>> df.take([-1, -2])
name class max_speed
1 monkey mammal NaN
3 lion mammal 80.5
>>> df.take([-1, -2], convert=False)
name class max_speed
1 monkey mammal NaN
3 lion mammal 80.5 |
Good catch, reason is very simple, it is not passed through: Lines 2140 to 2142 in d0d28fe
But not sure if this should actually be a public parameter |
Doh! Yeah, that's a good point. Drilling further down reveals more strangeness: pandas/pandas/core/internals.py Lines 4096 to 4099 in d0d28fe
The error message doesn't seem to match the check here IINM. |
xref pandas-devgh-16948. The parameter is not respected.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
[ci skip] xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
[ci skip] xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref gh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
xref pandas-devgh-16948. The parameter is not respected, nor is it a parameter in many 'take' implementations.
git diff upstream/master -u -- "*.py" | flake8 --diff