-
-
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
Changes from 7 commits
3e33406
1fc4b33
5270363
d4fd529
9a57c25
cf4999f
4cbaa48
8486969
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 |
---|---|---|
|
@@ -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 : keyword, value pairs | ||
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. I think we have a bug in the Not sure if I'm missing something, but why don't we have 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. Will fix to use I think it's confusing to use args.
You'd have to go digging into the numpy implementation to see what this whole axis thing is about. 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. +1 for using 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. I'm now confused @datapythonista . Should we use 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. I'll answer on the mailing list. Let's go for |
||
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)) | ||
|
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