From 5bbddce65870411979778c31ec0fc5cc4d5f19c8 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sat, 11 Jul 2020 02:01:32 +0200 Subject: [PATCH 01/29] DEPR - 18262 - deprecate lookup --- pandas/core/frame.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 10539ab74b4aa..4fa531a384df8 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3772,6 +3772,11 @@ def lookup(self, row_labels, col_labels) -> np.ndarray: Given equal-length arrays of row and column labels, return an array of the values corresponding to each (row, col) pair. + .. deprecated:: 1.1.0 + + DataFrame.lookup is deprecated, + use DataFrame.melt and DataFrame.loc instead. + Parameters ---------- row_labels : sequence @@ -3784,6 +3789,10 @@ def lookup(self, row_labels, col_labels) -> np.ndarray: numpy.ndarray The found values. """ + msg = ("The 'lookup' method is deprecated and will be" + "removed in a future version.") + warnings.warn(msg, FutureWarning, stacklevel=2) + n = len(row_labels) if n != len(col_labels): raise ValueError("Row labels must have same size as column labels") From 02b50ac61919af82b8aaabd42942b6411156d01e Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sat, 11 Jul 2020 02:02:15 +0200 Subject: [PATCH 02/29] DEPR - 18262 - changes black --- pandas/core/frame.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 4fa531a384df8..b753ce047e8bd 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3789,8 +3789,10 @@ def lookup(self, row_labels, col_labels) -> np.ndarray: numpy.ndarray The found values. """ - msg = ("The 'lookup' method is deprecated and will be" - "removed in a future version.") + msg = ( + "The 'lookup' method is deprecated and will be" + "removed in a future version." + ) warnings.warn(msg, FutureWarning, stacklevel=2) n = len(row_labels) From ca8bf053e065c0965b8278c6360720037380ee81 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sat, 11 Jul 2020 02:02:56 +0200 Subject: [PATCH 03/29] Add test for deprecation lookup --- pandas/tests/frame/indexing/test_indexing.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pandas/tests/frame/indexing/test_indexing.py b/pandas/tests/frame/indexing/test_indexing.py index 3fa3c9303806f..e401bfaf384f1 100644 --- a/pandas/tests/frame/indexing/test_indexing.py +++ b/pandas/tests/frame/indexing/test_indexing.py @@ -2229,3 +2229,12 @@ def test_object_casting_indexing_wraps_datetimelike(): assert blk.dtype == "m8[ns]" # we got the right block val = blk.iget((0, 0)) assert isinstance(val, pd.Timedelta) + + +def test_lookup_deprecated(): + # GH18262 + df = pd.DataFrame({'col': ["A", "A", "B", "B"], + 'A': [80, 23, np.nan, 22], + 'B': [80, 55, 76, 67]}) + with tm.assert_produces_warning(FutureWarning): + df.lookup(df.index, df['col']) From dea45b949aeeb0af5619e20080b0c25f3504d277 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sat, 11 Jul 2020 02:03:36 +0200 Subject: [PATCH 04/29] Added deprecation to whatsnew --- doc/source/whatsnew/v1.1.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index a4c107ddefd7b..7756a9d154758 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -824,6 +824,7 @@ Deprecations precision through the ``rtol``, and ``atol`` parameters, thus deprecating the ``check_less_precise`` parameter. (:issue:`13357`). - :func:`DataFrame.melt` accepting a value_name that already exists is deprecated, and will be removed in a future version (:issue:`34731`) +- :meth:`DataFrame.lookup` is deprecated and will be removed in a future version, use :meth:`DataFrame.melt` and :meth:`DataFrame.loc` instead (:issue:`18682`) .. --------------------------------------------------------------------------- From 5f116adbcade3ba0e8647d267f992010172a0a24 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sat, 11 Jul 2020 02:04:18 +0200 Subject: [PATCH 05/29] Add test for deprecation lookup --- pandas/tests/frame/indexing/test_indexing.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/tests/frame/indexing/test_indexing.py b/pandas/tests/frame/indexing/test_indexing.py index e401bfaf384f1..c48f5f3caec47 100644 --- a/pandas/tests/frame/indexing/test_indexing.py +++ b/pandas/tests/frame/indexing/test_indexing.py @@ -2233,8 +2233,8 @@ def test_object_casting_indexing_wraps_datetimelike(): def test_lookup_deprecated(): # GH18262 - df = pd.DataFrame({'col': ["A", "A", "B", "B"], - 'A': [80, 23, np.nan, 22], - 'B': [80, 55, 76, 67]}) + df = pd.DataFrame( + {"col": ["A", "A", "B", "B"], "A": [80, 23, np.nan, 22], "B": [80, 55, 76, 67]} + ) with tm.assert_produces_warning(FutureWarning): - df.lookup(df.index, df['col']) + df.lookup(df.index, df["col"]) From 0c04e903511b514823bfab1740181ebe74990694 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sat, 11 Jul 2020 19:15:02 +0200 Subject: [PATCH 06/29] FIX - 18262 - add warnings to other tests --- pandas/tests/frame/indexing/test_indexing.py | 27 +++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/pandas/tests/frame/indexing/test_indexing.py b/pandas/tests/frame/indexing/test_indexing.py index c48f5f3caec47..6aaed0add624d 100644 --- a/pandas/tests/frame/indexing/test_indexing.py +++ b/pandas/tests/frame/indexing/test_indexing.py @@ -1337,7 +1337,8 @@ def test_lookup_float(self, float_frame): df = float_frame rows = list(df.index) * len(df.columns) cols = list(df.columns) * len(df.index) - result = df.lookup(rows, cols) + with tm.assert_produces_warning(FutureWarning): + result = df.lookup(rows, cols) expected = np.array([df.loc[r, c] for r, c in zip(rows, cols)]) tm.assert_numpy_array_equal(result, expected) @@ -1346,7 +1347,8 @@ def test_lookup_mixed(self, float_string_frame): df = float_string_frame rows = list(df.index) * len(df.columns) cols = list(df.columns) * len(df.index) - result = df.lookup(rows, cols) + with tm.assert_produces_warning(FutureWarning): + result = df.lookup(rows, cols) expected = np.array( [df.loc[r, c] for r, c in zip(rows, cols)], dtype=np.object_ @@ -1362,7 +1364,8 @@ def test_lookup_bool(self): "mask_c": [False, True, False, True], } ) - df["mask"] = df.lookup(df.index, "mask_" + df["label"]) + with tm.assert_produces_warning(FutureWarning): + df["mask"] = df.lookup(df.index, "mask_" + df["label"]) exp_mask = np.array( [df.loc[r, c] for r, c in zip(df.index, "mask_" + df["label"])] @@ -1373,13 +1376,16 @@ def test_lookup_bool(self): def test_lookup_raises(self, float_frame): with pytest.raises(KeyError, match="'One or more row labels was not found'"): - float_frame.lookup(["xyz"], ["A"]) + with tm.assert_produces_warning(FutureWarning): + float_frame.lookup(["xyz"], ["A"]) with pytest.raises(KeyError, match="'One or more column labels was not found'"): - float_frame.lookup([float_frame.index[0]], ["xyz"]) + with tm.assert_produces_warning(FutureWarning): + float_frame.lookup([float_frame.index[0]], ["xyz"]) with pytest.raises(ValueError, match="same size"): - float_frame.lookup(["a", "b", "c"], ["a"]) + with tm.assert_produces_warning(FutureWarning): + float_frame.lookup(["a", "b", "c"], ["a"]) def test_lookup_requires_unique_axes(self): # GH#33041 raise with a helpful error message @@ -1390,14 +1396,17 @@ def test_lookup_requires_unique_axes(self): # homogeneous-dtype case with pytest.raises(ValueError, match="requires unique index and columns"): - df.lookup(rows, cols) + with tm.assert_produces_warning(FutureWarning): + df.lookup(rows, cols) with pytest.raises(ValueError, match="requires unique index and columns"): - df.T.lookup(cols, rows) + with tm.assert_produces_warning(FutureWarning): + df.T.lookup(cols, rows) # heterogeneous dtype df["B"] = 0 with pytest.raises(ValueError, match="requires unique index and columns"): - df.lookup(rows, cols) + with tm.assert_produces_warning(FutureWarning): + df.lookup(rows, cols) def test_set_value(self, float_frame): for idx in float_frame.index: From 7ac3b32983deabca0a9ad76dd8e56ecf5e4ada53 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sat, 11 Jul 2020 19:39:31 +0200 Subject: [PATCH 07/29] DOC - 18262 - added example to lookup values --- doc/source/user_guide/indexing.rst | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/doc/source/user_guide/indexing.rst b/doc/source/user_guide/indexing.rst index 6843dd1eadc81..4ac5b69b9c66e 100644 --- a/doc/source/user_guide/indexing.rst +++ b/doc/source/user_guide/indexing.rst @@ -1475,17 +1475,22 @@ default value. s.get('a') # equivalent to s['a'] s.get('x', default=-1) -The :meth:`~pandas.DataFrame.lookup` method +Looking up values by index/column labels ------------------------------------------- Sometimes you want to extract a set of values given a sequence of row labels -and column labels, and the ``lookup`` method allows for this and returns a -NumPy array. For instance: +and column labels, this can be achieved by ``DataFrame.melt`` combined by filtering the corresponding +rows with ``DataFrame.query``. For instance: .. ipython:: python - dflookup = pd.DataFrame(np.random.rand(20, 4), columns = ['A', 'B', 'C', 'D']) - dflookup.lookup(list(range(0, 10, 2)), ['B', 'C', 'A', 'B', 'D']) + df = pd.DataFrame({'col':["A", "A", "B","B"], + 'A':[80, 23, np.nan,22], + 'B': [80, 55, 76, 67]}) + df + melt = dflookup.melt('col') + df['lookup'] = values.query('col == variable')['value'].to_numpy() + df .. _indexing.class: From 2ab80cf54b4f8e648000aed49914dd81ff67afec Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sat, 11 Jul 2020 19:42:41 +0200 Subject: [PATCH 08/29] DOC - 18262 - point to example in depr --- pandas/core/frame.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index fc39709ac16d3..1cf6bd1785e7f 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3800,6 +3800,7 @@ def lookup(self, row_labels, col_labels) -> np.ndarray: DataFrame.lookup is deprecated, use DataFrame.melt and DataFrame.loc instead. + See "Indexing and selecting data" in the user guide for an example. Parameters ---------- From 94a6c0f41f7ae173d395309d26d5d98a083cb494 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sat, 11 Jul 2020 20:07:16 +0200 Subject: [PATCH 09/29] FIX - 18262 - deprecation warning before summary --- pandas/core/frame.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 1cf6bd1785e7f..edca2e1b36202 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3791,17 +3791,18 @@ def _series(self): def lookup(self, row_labels, col_labels) -> np.ndarray: """ - Label-based "fancy indexing" function for DataFrame. - - Given equal-length arrays of row and column labels, return an - array of the values corresponding to each (row, col) pair. - .. deprecated:: 1.1.0 DataFrame.lookup is deprecated, use DataFrame.melt and DataFrame.loc instead. See "Indexing and selecting data" in the user guide for an example. + Label-based "fancy indexing" function for DataFrame. + + Given equal-length arrays of row and column labels, return an + array of the values corresponding to each (row, col) pair. + + Parameters ---------- row_labels : sequence From a33913140fb90a07997c6e9d57abd50511637ec8 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sat, 11 Jul 2020 20:07:38 +0200 Subject: [PATCH 10/29] FIX - 18262 - whitespaces after comma --- doc/source/user_guide/indexing.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/source/user_guide/indexing.rst b/doc/source/user_guide/indexing.rst index 4ac5b69b9c66e..69f9034a249cd 100644 --- a/doc/source/user_guide/indexing.rst +++ b/doc/source/user_guide/indexing.rst @@ -1484,11 +1484,11 @@ rows with ``DataFrame.query``. For instance: .. ipython:: python - df = pd.DataFrame({'col':["A", "A", "B","B"], - 'A':[80, 23, np.nan,22], + df = pd.DataFrame({'col': ["A", "A", "B", "B"], + 'A': [80, 23, np.nan, 22], 'B': [80, 55, 76, 67]}) df - melt = dflookup.melt('col') + melt = df.melt('col') df['lookup'] = values.query('col == variable')['value'].to_numpy() df From 269e4cccb9765f36fdadd19c63cb931999621645 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sat, 11 Jul 2020 20:10:17 +0200 Subject: [PATCH 11/29] FIX - 18262 - removed double line break --- pandas/core/frame.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index edca2e1b36202..7bafa5447a910 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3802,7 +3802,6 @@ def lookup(self, row_labels, col_labels) -> np.ndarray: Given equal-length arrays of row and column labels, return an array of the values corresponding to each (row, col) pair. - Parameters ---------- row_labels : sequence From 0c40d690a5fbe3756090dfe6bce7bc7a74e229fc Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sat, 11 Jul 2020 21:14:39 +0200 Subject: [PATCH 12/29] Fix variable in ipython --- doc/source/user_guide/indexing.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/user_guide/indexing.rst b/doc/source/user_guide/indexing.rst index 69f9034a249cd..ac61844b8d8c8 100644 --- a/doc/source/user_guide/indexing.rst +++ b/doc/source/user_guide/indexing.rst @@ -1489,7 +1489,7 @@ rows with ``DataFrame.query``. For instance: 'B': [80, 55, 76, 67]}) df melt = df.melt('col') - df['lookup'] = values.query('col == variable')['value'].to_numpy() + df['lookup'] = melt.query('col == variable')['value'].to_numpy() df .. _indexing.class: From 1ca23bc52d352c8b6fec0114a04ecad71dbf0586 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sun, 12 Jul 2020 11:01:03 +0200 Subject: [PATCH 13/29] 18262 - removed linebreak --- pandas/core/frame.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 7bafa5447a910..61b220d7cd9a1 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3792,10 +3792,8 @@ def _series(self): def lookup(self, row_labels, col_labels) -> np.ndarray: """ .. deprecated:: 1.1.0 - - DataFrame.lookup is deprecated, - use DataFrame.melt and DataFrame.loc instead. - See "Indexing and selecting data" in the user guide for an example. + DataFrame.lookup is deprecated, use DataFrame.melt and DataFrame.loc instead, + see "Indexing and selecting data" in the user guide for an example. Label-based "fancy indexing" function for DataFrame. From 6342ad244eb1f3aed1b88f222e4441812a4a9ead Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Wed, 15 Jul 2020 22:25:59 +0200 Subject: [PATCH 14/29] 18262 - replaced depr message --- pandas/core/frame.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index aa502153e21fa..127cdcb812d8f 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3804,15 +3804,15 @@ def _series(self): def lookup(self, row_labels, col_labels) -> np.ndarray: """ - .. deprecated:: 1.1.0 - DataFrame.lookup is deprecated, use DataFrame.melt and DataFrame.loc instead, - see "Indexing and selecting data" in the user guide for an example. - Label-based "fancy indexing" function for DataFrame. Given equal-length arrays of row and column labels, return an array of the values corresponding to each (row, col) pair. + .. deprecated:: 1.1.0 + DataFrame.lookup is deprecated, use DataFrame.melt and DataFrame.loc instead, + see "Indexing and selecting data" in the user guide for an example. + Parameters ---------- row_labels : sequence From 3dfe19d930502545e12712f1d596368a76635a61 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Wed, 15 Jul 2020 22:28:14 +0200 Subject: [PATCH 15/29] 18262 - line break too long line --- pandas/core/frame.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 127cdcb812d8f..f33c7e911b368 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3810,8 +3810,9 @@ def lookup(self, row_labels, col_labels) -> np.ndarray: array of the values corresponding to each (row, col) pair. .. deprecated:: 1.1.0 - DataFrame.lookup is deprecated, use DataFrame.melt and DataFrame.loc instead, - see "Indexing and selecting data" in the user guide for an example. + DataFrame.lookup is deprecated, + use DataFrame.melt and DataFrame.loc instead. + See "Indexing and selecting data" in the user guide for an example. Parameters ---------- From 187d47b4fb548a85648847e363db54009a511234 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Wed, 15 Jul 2020 22:31:18 +0200 Subject: [PATCH 16/29] 18262 - set header size --- doc/source/user_guide/indexing.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/source/user_guide/indexing.rst b/doc/source/user_guide/indexing.rst index ac61844b8d8c8..732871779afa9 100644 --- a/doc/source/user_guide/indexing.rst +++ b/doc/source/user_guide/indexing.rst @@ -1475,6 +1475,8 @@ default value. s.get('a') # equivalent to s['a'] s.get('x', default=-1) +.. _indexing.lookup + Looking up values by index/column labels ------------------------------------------- From 227fad5fd6f2bf4f2d52b19b588e643e79384ca3 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Tue, 28 Jul 2020 21:37:38 +0200 Subject: [PATCH 17/29] [FIX] - 18262 - removed extra dash header --- doc/source/user_guide/indexing.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/user_guide/indexing.rst b/doc/source/user_guide/indexing.rst index 732871779afa9..787b37894165a 100644 --- a/doc/source/user_guide/indexing.rst +++ b/doc/source/user_guide/indexing.rst @@ -1478,7 +1478,7 @@ default value. .. _indexing.lookup Looking up values by index/column labels -------------------------------------------- +---------------------------------------- Sometimes you want to extract a set of values given a sequence of row labels and column labels, this can be achieved by ``DataFrame.melt`` combined by filtering the corresponding From ce775ce66a0810af25bcc58e74015f541ee19ddc Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Tue, 28 Jul 2020 21:39:34 +0200 Subject: [PATCH 18/29] [FIX] - 18262 - reference to section in docs --- pandas/core/frame.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index ab4a5254fcac8..ad95583b11b68 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3818,7 +3818,9 @@ def lookup(self, row_labels, col_labels) -> np.ndarray: .. deprecated:: 1.1.0 DataFrame.lookup is deprecated, use DataFrame.melt and DataFrame.loc instead. - See "Indexing and selecting data" in the user guide for an example. + For an example see "Looking up values by index/column labels" + in the "Indexing and selecting data" section + in the user guide for an example. Parameters ---------- From 2ee7d09fd9dc9f319a70d44b9057dc4384c7d8f4 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Tue, 28 Jul 2020 21:47:37 +0200 Subject: [PATCH 19/29] [FIX] - 18262 - grammar / typos in docstring --- pandas/core/frame.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index ad95583b11b68..d0c7ea6c7367f 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3818,9 +3818,9 @@ def lookup(self, row_labels, col_labels) -> np.ndarray: .. deprecated:: 1.1.0 DataFrame.lookup is deprecated, use DataFrame.melt and DataFrame.loc instead. - For an example see "Looking up values by index/column labels" + For an example see "Looking up values by index/column labels" in the "Indexing and selecting data" section - in the user guide for an example. + in the user guide. Parameters ---------- From dc2d367efad43376582386685724c05828d8e6ad Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sun, 13 Sep 2020 20:53:44 +0200 Subject: [PATCH 20/29] moved depr version to 1.2 --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 93239c3053610..adbb2d3ef549b 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3869,7 +3869,7 @@ def lookup(self, row_labels, col_labels) -> np.ndarray: Given equal-length arrays of row and column labels, return an array of the values corresponding to each (row, col) pair. - .. deprecated:: 1.1.0 + .. deprecated:: 1.2.0 DataFrame.lookup is deprecated, use DataFrame.melt and DataFrame.loc instead. For an example see "Looking up values by index/column labels" From 293bd7a14f83fffd8282cdefdba115005be2d8d0 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sun, 13 Sep 2020 20:58:34 +0200 Subject: [PATCH 21/29] test with linking to user guide --- pandas/core/frame.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index adbb2d3ef549b..ec48e13439944 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3872,8 +3872,7 @@ def lookup(self, row_labels, col_labels) -> np.ndarray: .. deprecated:: 1.2.0 DataFrame.lookup is deprecated, use DataFrame.melt and DataFrame.loc instead. - For an example see "Looking up values by index/column labels" - in the "Indexing and selecting data" section + For an example see :meth:`~pandas.DataFrame.lookup` in the user guide. Parameters From cbca163fc870b5c4dcb9845c8fd457880f099b34 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sun, 13 Sep 2020 21:23:04 +0200 Subject: [PATCH 22/29] Remove line break --- pandas/core/frame.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index ec48e13439944..b2bd56c39fc78 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3865,7 +3865,6 @@ def _series(self): def lookup(self, row_labels, col_labels) -> np.ndarray: """ Label-based "fancy indexing" function for DataFrame. - Given equal-length arrays of row and column labels, return an array of the values corresponding to each (row, col) pair. From 4c3c16314d6637eebbc991eb51c9be8ddeed0d00 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Mon, 14 Sep 2020 23:14:28 +0200 Subject: [PATCH 23/29] Revert whatsnew v1.1.0 --- doc/source/whatsnew/v1.1.0.rst | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index af0897df1b79e..a49b29d691692 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -834,14 +834,9 @@ Deprecations - The ``squeeze`` keyword in :meth:`~DataFrame.groupby` is deprecated and will be removed in a future version (:issue:`32380`) - The ``tz`` keyword in :meth:`Period.to_timestamp` is deprecated and will be removed in a future version; use ``per.to_timestamp(...).tz_localize(tz)`` instead (:issue:`34522`) - :meth:`DatetimeIndex.to_perioddelta` is deprecated and will be removed in a future version. Use ``index - index.to_period(freq).to_timestamp()`` instead (:issue:`34853`) -- :meth:`util.testing.assert_almost_equal` now accepts both relative and absolute - precision through the ``rtol``, and ``atol`` parameters, thus deprecating the - ``check_less_precise`` parameter. (:issue:`13357`). -- :func:`DataFrame.melt` accepting a value_name that already exists is deprecated, and will be removed in a future version (:issue:`34731`) -- the ``center`` keyword in the :meth:`DataFrame.expanding` function is deprecated and will be removed in a future version (:issue:`20647`) -- :meth:`DataFrame.lookup` is deprecated and will be removed in a future version, use :meth:`DataFrame.melt` and :meth:`DataFrame.loc` instead (:issue:`18682`) -- The ``center`` keyword in the :meth:`DataFrame.expanding` function is deprecated and will be removed in a future version (:issue:`20647`) - :meth:`DataFrame.melt` accepting a ``value_name`` that already exists is deprecated, and will be removed in a future version (:issue:`34731`) +- The ``center`` keyword in the :meth:`DataFrame.expanding` function is deprecated and will be removed in a future version (:issue:`20647`) + .. --------------------------------------------------------------------------- From b5a34e336852b1aee1baf9d60ea5802041b4603c Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Mon, 14 Sep 2020 23:14:52 +0200 Subject: [PATCH 24/29] Added depr message in whatsnew v1.2.0 --- doc/source/whatsnew/v1.1.2.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/source/whatsnew/v1.1.2.rst b/doc/source/whatsnew/v1.1.2.rst index 81b8e7df11625..8f99aabc9580c 100644 --- a/doc/source/whatsnew/v1.1.2.rst +++ b/doc/source/whatsnew/v1.1.2.rst @@ -28,6 +28,15 @@ Fixed regressions .. --------------------------------------------------------------------------- +.. _whatsnew_112.deprecations: + +Deprecations +~~~~~~~~~~~~ + +- :meth:`DataFrame.lookup` is deprecated and will be removed in a future version, use :meth:`DataFrame.melt` and :meth:`DataFrame.loc` instead (:issue:`18682`) + +.. --------------------------------------------------------------------------- + .. _whatsnew_112.bug_fixes: Bug fixes From ba4fb8a990540d37bb6e9f9979a429f90a57b442 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Mon, 14 Sep 2020 23:30:49 +0200 Subject: [PATCH 25/29] replace query with loc --- doc/source/user_guide/indexing.rst | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/source/user_guide/indexing.rst b/doc/source/user_guide/indexing.rst index b57db33d5632c..840a23eca3b2e 100644 --- a/doc/source/user_guide/indexing.rst +++ b/doc/source/user_guide/indexing.rst @@ -1487,7 +1487,7 @@ Looking up values by index/column labels Sometimes you want to extract a set of values given a sequence of row labels and column labels, this can be achieved by ``DataFrame.melt`` combined by filtering the corresponding -rows with ``DataFrame.query``. For instance: +rows with ``DataFrame.loc``. For instance: .. ipython:: python @@ -1496,9 +1496,13 @@ rows with ``DataFrame.query``. For instance: 'B': [80, 55, 76, 67]}) df melt = df.melt('col') - df['lookup'] = melt.query('col == variable')['value'].to_numpy() + melt = melt.loc[melt['col'] == melt['variable'], 'value'] + df['lookup'] = melt.reset_index(drop=True) df +Formerly this could be achieved with the dedicated ``DataFrame.lookup`` method +which was deprecated in version 1.2.0. + .. _indexing.class: Index objects From 6b91db6cfe292a915fe6f3c93805d2ffb128aba1 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Mon, 14 Sep 2020 23:33:34 +0200 Subject: [PATCH 26/29] add melt and loc to depr msg --- pandas/core/frame.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 7aa15ef55f661..0afb5429a2611 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3867,6 +3867,8 @@ def lookup(self, row_labels, col_labels) -> np.ndarray: msg = ( "The 'lookup' method is deprecated and will be" "removed in a future version." + "You can use DataFrame.melt and DataFrame.loc" + "as a substitute" ) warnings.warn(msg, FutureWarning, stacklevel=2) From ff7724f1697af9522a68ffe2f3065377819a05cc Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Mon, 14 Sep 2020 23:35:10 +0200 Subject: [PATCH 27/29] add dot --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 0afb5429a2611..319003e50999f 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3868,7 +3868,7 @@ def lookup(self, row_labels, col_labels) -> np.ndarray: "The 'lookup' method is deprecated and will be" "removed in a future version." "You can use DataFrame.melt and DataFrame.loc" - "as a substitute" + "as a substitute." ) warnings.warn(msg, FutureWarning, stacklevel=2) From 104e3cb94c7606f3e6a5a9cf055f2a451d2e84a7 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Tue, 15 Sep 2020 13:55:06 +0200 Subject: [PATCH 28/29] added colon hyperlink --- doc/source/user_guide/indexing.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/user_guide/indexing.rst b/doc/source/user_guide/indexing.rst index 840a23eca3b2e..a579c28b0432e 100644 --- a/doc/source/user_guide/indexing.rst +++ b/doc/source/user_guide/indexing.rst @@ -1480,7 +1480,7 @@ default value. s.get('a') # equivalent to s['a'] s.get('x', default=-1) -.. _indexing.lookup +.. _indexing.lookup: Looking up values by index/column labels ---------------------------------------- From 25e78ddcf24032e739a09701a1028246fe8e6740 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Wed, 16 Sep 2020 19:57:51 +0200 Subject: [PATCH 29/29] updates --- doc/source/user_guide/indexing.rst | 3 +-- doc/source/whatsnew/v1.1.2.rst | 9 --------- doc/source/whatsnew/v1.2.0.rst | 1 + 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/doc/source/user_guide/indexing.rst b/doc/source/user_guide/indexing.rst index a579c28b0432e..b11baad1e3eb5 100644 --- a/doc/source/user_guide/indexing.rst +++ b/doc/source/user_guide/indexing.rst @@ -1497,8 +1497,7 @@ rows with ``DataFrame.loc``. For instance: df melt = df.melt('col') melt = melt.loc[melt['col'] == melt['variable'], 'value'] - df['lookup'] = melt.reset_index(drop=True) - df + melt.reset_index(drop=True) Formerly this could be achieved with the dedicated ``DataFrame.lookup`` method which was deprecated in version 1.2.0. diff --git a/doc/source/whatsnew/v1.1.2.rst b/doc/source/whatsnew/v1.1.2.rst index 8f99aabc9580c..81b8e7df11625 100644 --- a/doc/source/whatsnew/v1.1.2.rst +++ b/doc/source/whatsnew/v1.1.2.rst @@ -28,15 +28,6 @@ Fixed regressions .. --------------------------------------------------------------------------- -.. _whatsnew_112.deprecations: - -Deprecations -~~~~~~~~~~~~ - -- :meth:`DataFrame.lookup` is deprecated and will be removed in a future version, use :meth:`DataFrame.melt` and :meth:`DataFrame.loc` instead (:issue:`18682`) - -.. --------------------------------------------------------------------------- - .. _whatsnew_112.bug_fixes: Bug fixes diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index 8b18b56929acd..41cf1218261ba 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -209,6 +209,7 @@ Deprecations - Deprecated parameter ``inplace`` in :meth:`MultiIndex.set_codes` and :meth:`MultiIndex.set_levels` (:issue:`35626`) - Deprecated parameter ``dtype`` in :~meth:`Index.copy` on method all index classes. Use the :meth:`Index.astype` method instead for changing dtype(:issue:`35853`) - Date parser functions :func:`~pandas.io.date_converters.parse_date_time`, :func:`~pandas.io.date_converters.parse_date_fields`, :func:`~pandas.io.date_converters.parse_all_fields` and :func:`~pandas.io.date_converters.generic_parser` from ``pandas.io.date_converters`` are deprecated and will be removed in a future version; use :func:`to_datetime` instead (:issue:`35741`) +- :meth:`DataFrame.lookup` is deprecated and will be removed in a future version, use :meth:`DataFrame.melt` and :meth:`DataFrame.loc` instead (:issue:`18682`) .. ---------------------------------------------------------------------------