-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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: update the DataFrame.reindex_like docstring #22775
DOC: update the DataFrame.reindex_like docstring #22775
Conversation
Hello @math-and-data! Thanks for updating the PR.
Comment last updated on November 04, 2018 at 21:16 Hours UTC |
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.
Thanks for working on the docstrings!
Added some first comments.
Can you make sure to run the validation script on all docstrings you edited? (not only for reindex_like
)
pandas/core/generic.py
Outdated
|
||
Returns | ||
------- | ||
reindexed : same as input | ||
Object | ||
same object type as input, but with changed indices on each axis |
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 can leave out the "Object" line, and directly put the explanation on that line.
And can you use Capital first character and end point punctuation?
Codecov Report
@@ Coverage Diff @@
## master #22775 +/- ##
==========================================
+ Coverage 92.29% 92.29% +<.01%
==========================================
Files 161 161
Lines 51500 51501 +1
==========================================
+ Hits 47531 47534 +3
+ Misses 3969 3967 -2
Continue to review full report at Codecov.
|
|
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, added some comments about formatting
pandas/core/frame.py
Outdated
keys : column label or list of column labels / arrays | ||
keys : str or list of str or array | ||
Column label or list of column labels / arrays that will | ||
form the new index. | ||
drop : boolean, default True |
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 replace all the boolean
by bool
? I think the validation script should warn about it now.
pandas/core/frame.py
Outdated
-------- | ||
DataFrame.set_index : opposite of reset_index | ||
DataFrame.reindex : change to new indices or expand indices | ||
DataFrame.reindex_like : change to same indices as other DataFrame |
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 capitalize the first letter of each description, and add a period at the end please
pandas/core/generic.py
Outdated
Conform the object to the same index on all axes. Optional | ||
filling logic, placing NA/NaN in locations having no value | ||
in the previous index. A new object is produced unless the | ||
new index is equivalent to the current one and copy=False. | ||
|
||
Parameters | ||
---------- | ||
other : 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.
I guess other
can only be Series
and DataFrame
? Or can we be more specific?
pandas/core/generic.py
Outdated
valid | ||
* backfill / bfill: use next valid observation to fill gap | ||
* nearest: use nearest valid observations to fill gap | ||
|
||
copy : boolean, default True |
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.
again, bool
instead of boolean
pandas/core/generic.py
Outdated
method : string or None | ||
Its row and column indices are used to define the new indices | ||
of this object. | ||
method : {None, 'backfill'/'bfill', 'pad'/'ffill', 'nearest'}, optional |
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'd remove the None
as it's already clear with the optional
pandas/core/generic.py
Outdated
|
||
.. versionadded:: 0.21.0 (list-like tolerance) | ||
|
||
Notes | ||
----- | ||
Like calling s.reindex(index=other.index, columns=other.columns, | ||
method=...) | ||
Like calling `.reindex(index=other.index, columns=other.columns, ...)` |
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 finish with a period.
pandas/core/generic.py
Outdated
-------- | ||
DataFrame.set_index : set row labels | ||
DataFrame.reset_index : remove row labels or move them to new columns | ||
DataFrame.reindex_like : change to same indices as other DataFrame |
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.
Again, capitalize and finish with periods.
pandas/core/generic.py
Outdated
DataFrame.set_index : set row labels | ||
DataFrame.reset_index : remove row labels or move them to new columns | ||
DataFrame.reindex : change to new indices or expand indices | ||
DataFrame.reindex_like : change to same indices as other DataFrame |
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.
same
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 capitalize and finish with period these descriptions.
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.
Great changes, few more minor things, and I think we're ready to merge. Thanks!
pandas/core/generic.py
Outdated
|
||
Returns | ||
------- | ||
reindexed : same as input | ||
Same object type as input, but with changed indices on each axis. |
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 add a line before that with Series or DataFrame
. This description should be indented in the next line.
pandas/core/generic.py
Outdated
@@ -3714,27 +3769,27 @@ def reindex(self, *args, **kwargs): | |||
New labels / index to conform to. Preferably an Index object to |
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 move the (should be specified using keywords)
to the description. As a normal sentence, doesn't need to be in brackets.
pandas/core/generic.py
Outdated
DataFrame.set_index : set row labels | ||
DataFrame.reset_index : remove row labels or move them to new columns | ||
DataFrame.reindex : change to new indices or expand indices | ||
DataFrame.reindex_like : change to same indices as other DataFrame |
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 capitalize and finish with period these descriptions.
pandas/core/generic.py
Outdated
DataFrame.set_index : set row labels | ||
DataFrame.reset_index : remove row labels or move them to new columns | ||
DataFrame.reindex : change to new indices or expand indices | ||
DataFrame.reindex_like : change to same indices as other DataFrame | ||
|
||
Returns | ||
------- | ||
reindexed : %(klass)s |
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.
reindexed : %(klass)s | |
%(klass)s |
And add a short description of what is being returned in the next line.
Co-Authored-By: math-and-data <math-and-data@users.noreply.github.com>
Co-Authored-By: math-and-data <math-and-data@users.noreply.github.com>
…data/pandas into docstring_reindex_like
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, really nice work.
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.
@math-and-data Nice enhancements! I added a few more comments, specifically on the wording of the summary lines.
Also, can you see if you can remove set_index
and reindex
from
Line 134 in 64c3491
-k"-axes -combine -itertuples -join -nunique -pivot_table -quantile -query -reindex -reindex_axis -replace -round -set_index -stack -to_stata" |
?
(so the doctests are run on our CI to make sure the examples are correct)
pandas/core/frame.py
Outdated
inplace : boolean, default False | ||
Modify the DataFrame in place (do not create a new object) | ||
verify_integrity : boolean, default False | ||
keys : str or list of str or array |
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.
To be strict, the keys can be something else as a string ... (column names can also be integers, timestamps, ..)
That also the reason that there was 'label' before.
pandas/core/frame.py
Outdated
verify_integrity : boolean, default False | ||
keys : str or list of str or array | ||
Column label or list of column labels / arrays that will | ||
form the new index. |
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.
Since this 'arrays' option is really something completely different (it are the actual index values passed as an array, not referring to one of the existing columns), I would put that in a separate sentence.
pandas/core/frame.py
Outdated
@@ -3909,43 +3909,59 @@ def shift(self, periods=1, freq=None, axis=0): | |||
def set_index(self, keys, drop=True, append=False, inplace=False, | |||
verify_integrity=False): | |||
""" | |||
An index is created with existing columns. |
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 find this a bit confusing as the summary line (because it seems to suggest that an index is returned, since that is created).
I found the previous "Set the DataFrame index using existing columns" a bit clearer. @datapythonista thoughts?
pandas/core/frame.py
Outdated
@@ -4037,6 +4049,8 @@ def set_index(self, keys, drop=True, append=False, inplace=False, | |||
def reset_index(self, level=None, drop=False, inplace=False, col_level=0, | |||
col_fill=''): | |||
""" | |||
An existing index is modified. |
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 think we can also do better here for the summary method, as just from this line "An existing index is modified.", a user won't get much clue of what the method is doing.
But of course, given that the method is doing different things, it might be difficult to have something that is still generally true but less vague as the above ...
Trying to think of better descriptions:
Remove index (level)
(but that is also a bit short / cryptic)
Reset index to default index or remove index level
(will think further on it)
pandas/core/generic.py
Outdated
|
||
.. versionadded:: 0.21.0 (list-like tolerance) | ||
|
||
Notes | ||
----- | ||
Like calling s.reindex(index=other.index, columns=other.columns, | ||
method=...) | ||
Like calling ``.reindex(index=other.index,columns=other.columns,...)``. |
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.
Like calling ``.reindex(index=other.index,columns=other.columns,...)``. | |
Like calling ``.reindex(index=other.index, columns=other.columns,...)``. |
@math-and-data do you have time to make the changes asked in the last review? |
@jorisvandenbossche addressed the comments from your code review. Let me know if there is anything else that needs to be changed. |
pandas/core/frame.py
Outdated
|
||
Reset the index of the DataFrame, and use the default one instead. | ||
If the DataFrame has a MultiIndex, this method can remove one or more | ||
of them. |
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 think levels
would be clearer than of them
pandas/core/generic.py
Outdated
Return an object with matching indices as other object. | ||
|
||
Conform the object to the same index on all axes. Optional | ||
filling logic, placing NA/NaN in locations having no 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.
Just say NaN
pandas/core/generic.py
Outdated
|
||
Returns | ||
------- | ||
reindexed : same as input | ||
Object with input data type, but with changed indices on each axis. |
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.
Replace everything before the comma with Same type as caller
pandas/core/generic.py
Outdated
|
||
Examples | ||
-------- | ||
>>> df_weather_station_1 = pd.DataFrame([[24.3, 75.7, 'high'], |
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 don't think the _weather_station
bit adds any value; would be OK to just use df1
, df2
, etc...
@WillAyd made the changes, can you take a look? |
Thanks @math-and-data and @datapythonista ! |
Errors due to the fact that this method
.reindex_like()
can use the same input parameters as.reindex()
(I avoided copy/paste and referred to the other method instead)