From e4d0bf0f4581ab4abf5dabbd4854d51829f67898 Mon Sep 17 00:00:00 2001 From: nocibambi Date: Sat, 10 Mar 2018 21:13:42 +0100 Subject: [PATCH 1/6] DOC: update the Index.get_values docstring --- pandas/core/indexes/base.py | 39 ++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index fd1d3690e8a89..626c3b72c8d67 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -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`. + + Because this is a wrapper function around Index.values, it is useful + when one explicitly wants to use a getter. + + Returns + ------- + numpy.ndarray + A one-dimensional numpy `array` of the indexes. + + See Also + -------- + Index + The basic object storing axis labels for all pandas objects. + Index.values + 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__) From c568a2d33d7de71c9aa6dd4372273d3dc733570a Mon Sep 17 00:00:00 2001 From: nocibambi Date: Sat, 10 Mar 2018 22:56:06 +0100 Subject: [PATCH 2/6] Corrections --- pandas/core/indexes/base.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 626c3b72c8d67..d9a5456fa550b 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -682,22 +682,24 @@ def _values(self): def get_values(self): """ - Return `Index` data as an `ndarray`. + Return `Index` data as an `numpy.ndarray`. - Because this is a wrapper function around Index.values, it is useful - when one explicitly wants to use a getter. + 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. + A one-dimensional `numpy array` of the indexes. See Also -------- - Index - The basic object storing axis labels for all pandas objects. - Index.values - The original function around which `get_values` creates a wrapper. + Index.values : The original function around which `get_values` wraps. Examples -------- @@ -718,6 +720,13 @@ def get_values(self): >>> 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')) + >>> midx.ndim + 1 """ return self.values From fa869f4bdc1721edcc87603e49b960a4758db29e Mon Sep 17 00:00:00 2001 From: nocibambi Date: Sun, 11 Mar 2018 18:05:58 +0100 Subject: [PATCH 3/6] Corrected extended summary and quotes --- pandas/core/indexes/base.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index d9a5456fa550b..b7ecb5077dc01 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -684,22 +684,16 @@ def get_values(self): """ 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. + It is a getter wrapper around `Index.values`. Returns ------- numpy.ndarray - A one-dimensional `numpy array` of the indexes. + A one-dimensional numpy array of the indexes. See Also -------- - Index.values : The original function around which `get_values` wraps. + Index.values : The original function around which get_values wraps. Examples -------- From 726be2f9ce014f438a0a417e8c155565a420727f Mon Sep 17 00:00:00 2001 From: nocibambi Date: Sun, 11 Mar 2018 18:34:38 +0100 Subject: [PATCH 4/6] Correcting spaces, extended summary, multiIndex example --- pandas/core/indexes/base.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index b7ecb5077dc01..87900f333a450 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -684,12 +684,10 @@ def get_values(self): """ Return `Index` data as an `numpy.ndarray`. - It is a getter wrapper around `Index.values`. - Returns ------- numpy.ndarray - A one-dimensional numpy array of the indexes. + A one-dimensional numpy array of the `Index` values. See Also -------- @@ -718,7 +716,9 @@ def get_values(self): `MultiIndex` arrays also have only one dimension: >>> midx = pd.MultiIndex.from_arrays([[1, 2, 3], ['a', 'b', 'c']], - ... names = ('number', 'letter')) + ... names=('number', 'letter')) + >>> midx.get_values() + array([(1, 'a'), (2, 'b'), (3, 'c')], dtype=object) >>> midx.ndim 1 """ From 516181de16d020d5e0f3878d8df333f61e7ee4c4 Mon Sep 17 00:00:00 2001 From: nocibambi Date: Sun, 11 Mar 2018 18:38:24 +0100 Subject: [PATCH 5/6] See also correction --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 87900f333a450..1c8c753c92602 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -691,7 +691,7 @@ def get_values(self): See Also -------- - Index.values : The original function around which get_values wraps. + Index.values : The attribute that get_values wraps. Examples -------- From e2e0b4f5d735a4986aa09cc3328ffa58f5e6759e Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Sun, 11 Mar 2018 12:55:29 -0500 Subject: [PATCH 6/6] Multi ndim --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 1c8c753c92602..42a863a64ad04 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -719,7 +719,7 @@ def get_values(self): ... names=('number', 'letter')) >>> midx.get_values() array([(1, 'a'), (2, 'b'), (3, 'c')], dtype=object) - >>> midx.ndim + >>> midx.get_values().ndim 1 """ return self.values