Skip to content

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

Merged
merged 6 commits into from
Mar 11, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,44 @@ def _values(self):
return self.values

def get_values(self):
""" return the underlying data as an ndarray """
"""
Return `Index` data as an `ndarray`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ndarray -> numpy.ndarray


Because this is a wrapper function around Index.values, it is useful
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I suspect that the real reason for this is compatability with Series.get_values, which does more work (sparse transformation).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regardless. I would personally just omit this section.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validator requires an extended summary, so I would write about the reason you mention, but I do not find any information about 'sparse transformation'. Could you point me to a term/link on which I can follow up?

when one explicitly wants to use a getter.

Returns
-------
numpy.ndarray
A one-dimensional numpy `array` of the indexes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like MultiIndex.get_values inherits this docstring. Can you check the dimensionality of it? If it's a 2-D array I would note that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just checked, it is 1-D.

In [5]: midx = pd.MultiIndex.from_arrays([[1, 2, 3], ['a', 'b', 'c']], names =  ('number', 'letter'))
In [6]: midx.ndim
Out[6]: 1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, that is not what I would have expected :) Could you add that as an example?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although, I guess that makes sense since it's just self.values


See Also
--------
Index
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove Index I think.

The basic object storing axis labels for all pandas objects.
Index.values
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be Index.values : description I htink.

The original function around which `get_values` creates a wrapper.

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)
"""
return self.values

@Appender(IndexOpsMixin.memory_usage.__doc__)
Expand Down