DOC: update the DataFrame.reindex_like docstring#22775
DOC: update the DataFrame.reindex_like docstring#22775WillAyd merged 19 commits intopandas-dev:masterfrom
Conversation
|
Hello @math-and-data! Thanks for updating the PR.
Comment last updated on November 04, 2018 at 21:16 Hours UTC |
jorisvandenbossche
left a comment
There was a problem hiding this comment.
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
| ------- | ||
| reindexed : same as input | ||
| Object | ||
| same object type as input, but with changed indices on each axis |
There was a problem hiding this comment.
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.
|
|
datapythonista
left a comment
There was a problem hiding this comment.
Looks good, added some comments about formatting
pandas/core/frame.py
Outdated
| 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.
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.
Can you capitalize the first letter of each description, and add a period at the end please
pandas/core/generic.py
Outdated
|
|
||
| Parameters | ||
| ---------- | ||
| other : Object |
There was a problem hiding this comment.
I guess other can only be Series and DataFrame? Or can we be more specific?
pandas/core/generic.py
Outdated
| * 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.
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.
I'd remove the None as it's already clear with the optional
pandas/core/generic.py
Outdated
| ----- | ||
| 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.
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.
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.
Can you capitalize and finish with period these descriptions.
datapythonista
left a comment
There was a problem hiding this comment.
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.
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.
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.
Can you capitalize and finish with period these descriptions.
pandas/core/generic.py
Outdated
|
|
||
| Returns | ||
| ------- | ||
| reindexed : %(klass)s |
There was a problem hiding this comment.
| 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
datapythonista
left a comment
There was a problem hiding this comment.
lgtm, really nice work.
jorisvandenbossche
left a comment
There was a problem hiding this comment.
@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
?
(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.
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.
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
| 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.
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
| 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.
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
| ----- | ||
| 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.
| 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.
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 |
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.
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.
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)