-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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: Improve docstring for pandas.Index.repeat #19985
Merged
jorisvandenbossche
merged 8 commits into
pandas-dev:master
from
alysivji:doc_index-repeat
Mar 9, 2018
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3e33406
Fix docstring
alysivji 1fc4b33
Update location of underlying numpy function
alysivji 5270363
Update with PR comments
alysivji d4fd529
Simplify docstring
alysivji 9a57c25
Update for change in the docstring guide
jorisvandenbossche cf4999f
Add kwargs to parameters list
alysivji 4cbaa48
Merge branch 'doc_index-repeat' of github.com:alysivji/pandas into do…
alysivji 8486969
Fix keyword argument parameter in docstring
alysivji File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -696,12 +696,38 @@ def memory_usage(self, deep=False): | |
@deprecate_kwarg(old_arg_name='n', new_arg_name='repeats') | ||
def repeat(self, repeats, *args, **kwargs): | ||
""" | ||
Repeat elements of an Index. Refer to `numpy.ndarray.repeat` | ||
for more information about the `repeats` argument. | ||
Repeat elements of an Index. | ||
|
||
See also | ||
Returns a new index where each element of the current index | ||
is repeated consecutively a given number of times. | ||
|
||
Parameters | ||
---------- | ||
repeats : int | ||
The number of repetitions for each element. | ||
**kwargs | ||
Additional keywords have no effect but might be accepted for | ||
compatibility with numpy. | ||
|
||
Returns | ||
------- | ||
pandas.Index | ||
Newly created Index with repeated elements. | ||
|
||
See Also | ||
-------- | ||
Series.repeat : Equivalent function for Series | ||
numpy.repeat : Underlying implementation | ||
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. May be we could have the |
||
|
||
Examples | ||
-------- | ||
numpy.ndarray.repeat | ||
>>> idx = pd.Index([1, 2, 3]) | ||
>>> idx | ||
Int64Index([1, 2, 3], dtype='int64') | ||
>>> idx.repeat(2) | ||
Int64Index([1, 1, 2, 2, 3, 3], dtype='int64') | ||
>>> idx.repeat(3) | ||
Int64Index([1, 1, 1, 2, 2, 2, 3, 3, 3], dtype='int64') | ||
""" | ||
nv.validate_repeat(args, kwargs) | ||
return self._shallow_copy(self._values.repeat(repeats)) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
There is still some discussion on whether we want to document
args
andkwargs
, but I think we should. If they are ignored, I think it'd be useful for users (and also developers) to know it, and why they are present. If they are being sent to numpy, that's also something worth mentioning.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.
these are for numpy compat (only a small set of methods are like this). see the validate_repeat below.
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.
In this case the
*kwargs
are not ignored, but you get an informative error message if you try to pass any additional keyword (also in case of the numpy ones likeaxis
). So therefore I would personally not document 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 would agree that mentioned **kwargs are for numpy compat is not a bad idea
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 thought it was only for the nice error message, but indeed it is also accepting (not raising) the argument when it is the default value (in this case
axis=None
).In that case, it's fine for me as well to actually document this