-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: update the Index.get_values docstring #20231
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
Changes from 2 commits
e4d0bf0
c568a2d
fa869f4
726be2f
516181d
e2e0b4f
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 |
---|---|---|
|
@@ -681,7 +681,53 @@ def _values(self): | |
return self.values | ||
|
||
def get_values(self): | ||
""" return the underlying data as an ndarray """ | ||
""" | ||
Return `Index` data as an `numpy.ndarray`. | ||
|
||
In its functionality it is the same as `Series.get_values`, | ||
but because it refers only to `Index` values, it does not need | ||
the additional sparse transformation work. | ||
|
||
It is a getter wrapper around `Index.values`. Getters are | ||
often considered non-pythonic and, therefore, should be avoided if are | ||
not explicitly aimed for. | ||
|
||
Returns | ||
------- | ||
numpy.ndarray | ||
A one-dimensional `numpy array` of the indexes. | ||
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. don't need quotes around numpy array |
||
|
||
See Also | ||
-------- | ||
Index.values : The original function around which `get_values` wraps. | ||
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. don't need the quotes here |
||
|
||
Examples | ||
-------- | ||
Getting the `Index` values of a `DataFrame`: | ||
|
||
>>> df = pd.DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, 9]], | ||
... index=['a', 'b', 'c'], columns=['A', 'B', 'C']) | ||
>>> df | ||
A B C | ||
a 1 2 3 | ||
b 4 5 6 | ||
c 7 8 9 | ||
>>> df.index.get_values() | ||
array(['a', 'b', 'c'], dtype=object) | ||
|
||
Standalone `Index` values: | ||
|
||
>>> idx = pd.Index(['1', '2', '3']) | ||
>>> idx.get_values() | ||
array(['1', '2', '3'], dtype=object) | ||
|
||
`MultiIndex` arrays also have only one dimension: | ||
|
||
>>> midx = pd.MultiIndex.from_arrays([[1, 2, 3], ['a', 'b', 'c']], | ||
... names = ('number', 'letter')) | ||
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. PEP8: no spaces around the |
||
>>> midx.ndim | ||
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. Better to show |
||
1 | ||
""" | ||
return self.values | ||
|
||
@Appender(IndexOpsMixin.memory_usage.__doc__) | ||
|
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.
the extended description is not very useful here. you can just say that this is a wrapper around .values