From 108a6923a6d7ba4349511fefe7452c9c32a74641 Mon Sep 17 00:00:00 2001 From: Michael Grund <23025878+michaelgrund@users.noreply.github.com> Date: Sun, 12 Sep 2021 18:17:34 +0200 Subject: [PATCH 1/4] Figure.wiggle: Deprecate parameter "columns" to "incols" (remove in v0.6.0) --- pygmt/src/wiggle.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pygmt/src/wiggle.py b/pygmt/src/wiggle.py index f7a24cd6dc4..c97893e54cc 100644 --- a/pygmt/src/wiggle.py +++ b/pygmt/src/wiggle.py @@ -2,10 +2,11 @@ wiggle - Plot z=f(x,y) anomalies along tracks. """ from pygmt.clib import Session -from pygmt.helpers import build_arg_string, fmt_docstring, kwargs_to_strings, use_alias +from pygmt.helpers import build_arg_string, fmt_docstring, kwargs_to_strings, use_alias, deprecate_parameter @fmt_docstring +@deprecate_parameter("columns", "incols", "v0.4.1", remove_version="v0.6.0") @use_alias( B="frame", D="position", @@ -25,7 +26,7 @@ e="find", g="gap", h="header", - i="columns", + i="incols", p="perspective", ) @kwargs_to_strings(R="sequence", c="sequence_comma", i="sequence_comma", p="sequence") @@ -49,7 +50,7 @@ def wiggle(self, x=None, y=None, z=None, data=None, **kwargs): data : str or {table-like} Pass in either a file name to an ASCII data table, a 2D {table-classes}. - Use parameter ``columns`` to choose which columns are x, y, z, + Use parameter ``incols`` to choose which columns are x, y, z, respectively. {J} {R} @@ -86,11 +87,7 @@ def wiggle(self, x=None, y=None, z=None, data=None, **kwargs): {e} {g} {h} - columns : str or 1d array - Choose which columns are x, y, and z, respectively if input is provided - via *data*. E.g. ``columns = [0, 1, 2]`` or ``columns = "0,1,2"`` if - the *x* values are stored in the first column, *y* values in the second - one and *z* values in the third one. Note: zero-based indexing is used. + {i} {p} """ kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access From dc2bd8facf4b7633aced5f060dc550d09d09cf24 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Sun, 12 Sep 2021 18:36:15 +0200 Subject: [PATCH 2/4] formatting --- pygmt/src/wiggle.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pygmt/src/wiggle.py b/pygmt/src/wiggle.py index c97893e54cc..f67c8c132da 100644 --- a/pygmt/src/wiggle.py +++ b/pygmt/src/wiggle.py @@ -2,11 +2,17 @@ wiggle - Plot z=f(x,y) anomalies along tracks. """ from pygmt.clib import Session -from pygmt.helpers import build_arg_string, fmt_docstring, kwargs_to_strings, use_alias, deprecate_parameter +from pygmt.helpers import ( + build_arg_string, + deprecate_parameter, + fmt_docstring, + kwargs_to_strings, + use_alias, +) @fmt_docstring -@deprecate_parameter("columns", "incols", "v0.4.1", remove_version="v0.6.0") +@deprecate_parameter("columns", "incols", "v0.5.0", remove_version="v0.7.0") @use_alias( B="frame", D="position", From 152704b118e011aa43b61528f08c722931e26bb3 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Sun, 12 Sep 2021 19:19:12 +0200 Subject: [PATCH 3/4] add test to check deprectation warning --- pygmt/tests/test_wiggle.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/pygmt/tests/test_wiggle.py b/pygmt/tests/test_wiggle.py index 7bd92e15bb1..bd493643c3c 100644 --- a/pygmt/tests/test_wiggle.py +++ b/pygmt/tests/test_wiggle.py @@ -29,3 +29,36 @@ def test_wiggle(): position="jRM+w2+lnT", ) return fig + + +@pytest.mark.mpl_image_compare(filename="test_wiggle.png") +def test_wiggle_deprecate_columns_to_incols(): + """ + Make sure that the old parameter "columns" is supported and it reports a + warning. + + Modified from the test_wiggle() test. + """ + + # put data into numpy array and swap x and y columns + # as the use of the 'columns' parameter will reverse this action + x = np.arange(-2, 2, 0.02) + y = np.zeros(x.size) + z = np.cos(2 * np.pi * x) + data = np.array([y, x, z]) + + fig = Figure() + with pytest.warns(expected_warning=FutureWarning) as record: + fig.wiggle( + region=[-4, 4, -1, 1], + projection="X8c", + data=data, + columns=[1, 0, 2], + scale="0.5c", + color=["red+p", "gray+n"], + pen="1.0p", + track="0.5p", + position="jRM+w2+lnT", + ) + assert len(record) == 1 # check that only one warning was raised + return fig From f639382762ed23e9de9db101d91dd898bb557d1f Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Sun, 12 Sep 2021 19:39:26 +0200 Subject: [PATCH 4/4] adjust test --- pygmt/tests/test_wiggle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/tests/test_wiggle.py b/pygmt/tests/test_wiggle.py index bd493643c3c..09c1d5c10ea 100644 --- a/pygmt/tests/test_wiggle.py +++ b/pygmt/tests/test_wiggle.py @@ -45,7 +45,7 @@ def test_wiggle_deprecate_columns_to_incols(): x = np.arange(-2, 2, 0.02) y = np.zeros(x.size) z = np.cos(2 * np.pi * x) - data = np.array([y, x, z]) + data = np.array([y, x, z]).T fig = Figure() with pytest.warns(expected_warning=FutureWarning) as record: