From 34e5fc62390e2b3ffe64afcefa9757d55b07c45a Mon Sep 17 00:00:00 2001 From: Alan Hogue Date: Mon, 3 Dec 2018 17:07:19 -0800 Subject: [PATCH 01/10] Corrects 'reindex_axis' docstring. The docstring included a 'tolerance' parameter which is missing from the source. This has been removed. The docstring did not describe the 'fill_value' parameter. This has been added, mostly reusing the wording in the summary part of the existing docstring. --- pandas/core/generic.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 08c07da39128f..cbb1c5302cd1e 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4338,16 +4338,8 @@ def _reindex_multi(self, axes, copy, fill_value): passed MultiIndex level limit : int, default None Maximum number of consecutive elements to forward or backward fill - tolerance : optional - Maximum distance between original and new labels for inexact - matches. The values of the index at the matching locations most - satisfy the equation ``abs(index[indexer] - target) <= tolerance``. - - Tolerance may be a scalar value, which applies the same tolerance - to all values, or list-like, which applies variable tolerance per - element. List-like includes list, tuple, array, Series, and must be - the same size as the index and its dtype must exactly match the - index's type. + fill_value : float, default NaN + Value used to fill in locations having no value in the previous index. .. versionadded:: 0.21.0 (list-like tolerance) From ffbad458820987d6a3f7fbb72611506a58f20387 Mon Sep 17 00:00:00 2001 From: Alan Hogue Date: Tue, 4 Dec 2018 16:53:15 -0800 Subject: [PATCH 02/10] Minor PEP-8 change to previous commit Shortened description line of 'fill_value' in 'reindex_axis'. --- pandas/core/generic.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index cbb1c5302cd1e..a59279134dc2a 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4339,7 +4339,8 @@ def _reindex_multi(self, axes, copy, fill_value): limit : int, default None Maximum number of consecutive elements to forward or backward fill fill_value : float, default NaN - Value used to fill in locations having no value in the previous index. + Value used to fill in locations having no value in the previous + index. .. versionadded:: 0.21.0 (list-like tolerance) From b54ea1d7f8fcc126b96980137ecfe1259cfa703e Mon Sep 17 00:00:00 2001 From: Alan Hogue Date: Tue, 4 Dec 2018 20:31:16 -0800 Subject: [PATCH 03/10] Fixed non-functioning example. Added periods, reformatted summary, and other changes required by validate_docstrings.py. --- pandas/core/generic.py | 46 +++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a59279134dc2a..59b90bbde8550 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4311,39 +4311,46 @@ def _needs_reindex_multi(self, axes, method, level): def _reindex_multi(self, axes, copy, fill_value): return NotImplemented - _shared_docs['reindex_axis'] = ("""Conform input object to new index - with optional filling logic, placing NA/NaN in locations having - no value in the previous index. A new object is produced unless - the new index is equivalent to the current one and copy=False. + _shared_docs['reindex_axis'] = (""" + Conform input object to new index. + + By default, places NA/NaN in locations having no value in the + previous index. A new object is produced unless the new index + is equivalent to the current one and copy=False. Parameters ---------- labels : array-like New labels / index to conform to. Preferably an Index object to - avoid duplicating data + avoid duplicating data. axis : %(axes_single_arg)s + Indicate whether to use rows or columns. method : {None, 'backfill'/'bfill', 'pad'/'ffill', 'nearest'}, optional Method to use for filling holes in reindexed DataFrame: - * default: don't fill gaps + * default: don't fill gaps. * pad / ffill: propagate last valid observation forward to next - valid - * backfill / bfill: use next valid observation to fill gap - * nearest: use nearest valid observations to fill gap + valid. + * backfill / bfill: use next valid observation to fill gap. + * nearest: use nearest valid observations to fill gap. - copy : boolean, default True - Return a new object, even if the passed indexes are the same level : int or name Broadcast across a level, matching Index values on the - passed MultiIndex level + passed MultiIndex level. + copy : bool, default True + Return a new object, even if the passed indexes are the same. limit : int, default None - Maximum number of consecutive elements to forward or backward fill + Maximum number of consecutive elements to forward or backward fill. fill_value : float, default NaN Value used to fill in locations having no value in the previous index. .. versionadded:: 0.21.0 (list-like tolerance) + Returns + ------- + %(klass)s + See Also -------- DataFrame.set_index : Set row labels. @@ -4351,13 +4358,16 @@ def _reindex_multi(self, axes, copy, fill_value): DataFrame.reindex : Change to new indices or expand indices. DataFrame.reindex_like : Change to same indices as other DataFrame. - Returns - ------- - %(klass)s - Examples -------- - >>> df.reindex_axis(['A', 'B', 'C'], axis=1) + >>> df = pd.DataFrame(np.array(([1,2,3], [4,5,6], [7,8,9])), + ... index=['One', 'Two', 'Three'], + ... columns=['A', 'B', 'C']) + >>> df.reindex_axis(['B', 'C', 'D'], axis=1) + B C D + One 2 3 NaN + Two 5 6 NaN + Three 8 9 NaN """) @Appender(_shared_docs['reindex_axis'] % _shared_doc_kwargs) From 43f73dd56857696911ff8629aa72b860b76735e8 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Wed, 5 Dec 2018 11:19:27 -0800 Subject: [PATCH 04/10] Update pandas/core/generic.py Co-Authored-By: eahogue --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 59b90bbde8550..754990b584995 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4314,7 +4314,7 @@ def _reindex_multi(self, axes, copy, fill_value): _shared_docs['reindex_axis'] = (""" Conform input object to new index. - By default, places NA/NaN in locations having no value in the + By default, places NaN in locations having no value in the previous index. A new object is produced unless the new index is equivalent to the current one and copy=False. From dacc3d36db43daec958fbc88f4b8b79ed9970193 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Wed, 5 Dec 2018 11:19:45 -0800 Subject: [PATCH 05/10] Update pandas/core/generic.py Co-Authored-By: eahogue --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 754990b584995..902ecad4a1509 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4334,7 +4334,7 @@ def _reindex_multi(self, axes, copy, fill_value): * backfill / bfill: use next valid observation to fill gap. * nearest: use nearest valid observations to fill gap. - level : int or name + level : int or str Broadcast across a level, matching Index values on the passed MultiIndex level. copy : bool, default True From 5b460819303ec2a06f81bddab18ec50f20f69e6d Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Wed, 5 Dec 2018 11:20:06 -0800 Subject: [PATCH 06/10] Update pandas/core/generic.py Co-Authored-By: eahogue --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 902ecad4a1509..6f8cfbdd68c47 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4339,7 +4339,7 @@ def _reindex_multi(self, axes, copy, fill_value): passed MultiIndex level. copy : bool, default True Return a new object, even if the passed indexes are the same. - limit : int, default None + limit : int, optional Maximum number of consecutive elements to forward or backward fill. fill_value : float, default NaN Value used to fill in locations having no value in the previous From d61033976203dae3eef1701693d49f0674c60026 Mon Sep 17 00:00:00 2001 From: Alan Hogue Date: Wed, 5 Dec 2018 14:03:46 -0800 Subject: [PATCH 07/10] Mostly stylistic updates to reindex_axis docstring. --- pandas/core/generic.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 6f8cfbdd68c47..1040523b3fc40 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4350,6 +4350,8 @@ def _reindex_multi(self, axes, copy, fill_value): Returns ------- %(klass)s + Returns a new DataFrame object with new indices, unless the new + index is equivalent to the current one and copy=False. See Also -------- @@ -4360,14 +4362,16 @@ def _reindex_multi(self, axes, copy, fill_value): Examples -------- - >>> df = pd.DataFrame(np.array(([1,2,3], [4,5,6], [7,8,9])), - ... index=['One', 'Two', 'Three'], - ... columns=['A', 'B', 'C']) - >>> df.reindex_axis(['B', 'C', 'D'], axis=1) - B C D - One 2 3 NaN - Two 5 6 NaN - Three 8 9 NaN + >>> df = pd.DataFrame({'num_legs': [4, 2], 'num_wings': [0, 2]}, + ... index=['dog', 'hawk']) + >>> df + num_legs num_wings + dog 4 0 + hawk 2 2 + >>> df.reindex_axis(['num_wings', 'num_legs', 'num_heads'], axis='columns') + num_wings num_legs num_heads + dog 0 4 NaN + hawk 2 2 NaN """) @Appender(_shared_docs['reindex_axis'] % _shared_doc_kwargs) From c11052d16654cc0aa3d0d48a5e7985ce87183315 Mon Sep 17 00:00:00 2001 From: Alan Hogue Date: Thu, 6 Dec 2018 14:58:01 -0800 Subject: [PATCH 08/10] Adding deprecation note to reindex_axis docstring. --- pandas/core/generic.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 1040523b3fc40..939b6d119ffb8 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4318,6 +4318,9 @@ def _reindex_multi(self, axes, copy, fill_value): previous index. A new object is produced unless the new index is equivalent to the current one and copy=False. + .. deprecated:: 0.21.0 + Use `reindex` instead. + Parameters ---------- labels : array-like From 0a8456ccc209e62715fb0fe4157a9445f8924fc7 Mon Sep 17 00:00:00 2001 From: Alan Hogue Date: Sat, 8 Dec 2018 15:55:55 -0800 Subject: [PATCH 09/10] Minor lint fixes for line length and trailing spaces. --- pandas/core/generic.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 939b6d119ffb8..9cb7cc744d34e 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4345,7 +4345,7 @@ def _reindex_multi(self, axes, copy, fill_value): limit : int, optional Maximum number of consecutive elements to forward or backward fill. fill_value : float, default NaN - Value used to fill in locations having no value in the previous + Value used to fill in locations having no value in the previous index. .. versionadded:: 0.21.0 (list-like tolerance) @@ -4353,7 +4353,7 @@ def _reindex_multi(self, axes, copy, fill_value): Returns ------- %(klass)s - Returns a new DataFrame object with new indices, unless the new + Returns a new DataFrame object with new indices, unless the new index is equivalent to the current one and copy=False. See Also @@ -4371,7 +4371,8 @@ def _reindex_multi(self, axes, copy, fill_value): num_legs num_wings dog 4 0 hawk 2 2 - >>> df.reindex_axis(['num_wings', 'num_legs', 'num_heads'], axis='columns') + >>> df.reindex_axis(['num_wings', 'num_legs', 'num_heads'], + ... axis='columns') num_wings num_legs num_heads dog 0 4 NaN hawk 2 2 NaN From 201ef537dd5003f28c0f56863da9fc817b70392a Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Sun, 9 Dec 2018 09:01:30 +0100 Subject: [PATCH 10/10] move deprecated --- pandas/core/generic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index eb7881b540b2d..1e26c3f45f660 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4361,13 +4361,13 @@ def _reindex_multi(self, axes, copy, fill_value): _shared_docs['reindex_axis'] = (""" Conform input object to new index. + .. deprecated:: 0.21.0 + Use `reindex` instead. + By default, places NaN in locations having no value in the previous index. A new object is produced unless the new index is equivalent to the current one and copy=False. - .. deprecated:: 0.21.0 - Use `reindex` instead. - Parameters ---------- labels : array-like