From 7b2ff17ae3acc38bfd8793b64b1bb53493c07103 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 27 Sep 2021 11:18:54 +0800 Subject: [PATCH 1/4] Figure.wiggle: Reorder input parameter to 'data, x, y, z' --- pygmt/src/wiggle.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pygmt/src/wiggle.py b/pygmt/src/wiggle.py index 9c97858f149..39e718cf8fd 100644 --- a/pygmt/src/wiggle.py +++ b/pygmt/src/wiggle.py @@ -4,6 +4,7 @@ from pygmt.clib import Session from pygmt.helpers import ( build_arg_string, + check_data_input_order, deprecate_parameter, fmt_docstring, kwargs_to_strings, @@ -13,6 +14,7 @@ @fmt_docstring @deprecate_parameter("columns", "incols", "v0.5.0", remove_version="v0.7.0") +@check_data_input_order("v0.5.0", remove_version="v0.7.0") @use_alias( B="frame", D="position", @@ -39,7 +41,7 @@ w="wrap", ) @kwargs_to_strings(R="sequence", c="sequence_comma", i="sequence_comma", p="sequence") -def wiggle(self, x=None, y=None, z=None, data=None, **kwargs): +def wiggle(self, data=None, x=None, y=None, z=None, **kwargs): r""" Plot z=f(x,y) anomalies along tracks. From 95fa173cbba251096ab0f22764cbfb11824cd07b Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 27 Sep 2021 17:37:35 +0800 Subject: [PATCH 2/4] Fix the check_data_input_order decorator --- pygmt/helpers/decorators.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pygmt/helpers/decorators.py b/pygmt/helpers/decorators.py index ce6fd0abd6b..4c47ae771bc 100644 --- a/pygmt/helpers/decorators.py +++ b/pygmt/helpers/decorators.py @@ -11,6 +11,7 @@ from inspect import Parameter, signature import numpy as np +import pygmt from pygmt.exceptions import GMTInvalidInput from pygmt.helpers.utils import is_nonstr_iter @@ -857,7 +858,14 @@ def new_module(*args, **kwargs): New module instance that raises a warning if positional arguments are passed. """ - if len(args) > 0: # positional arguments are used + # plotting function always has the "self" parameter + if len(args) > 1 and isinstance(args[0], pygmt.Figure): + plotting_func = 1 + else: + plotting_func = 0 + + if len(args) > 1 + plotting_func: + # more than one positional arguments are used msg = ( "The function parameters has been re-ordered as 'data, x, y, [z]' " f"since {deprecate_version} but you're passing positional arguments. " From 7e6204d12f9a76d04384263a29121040a09d2847 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 30 Sep 2021 14:58:10 +0800 Subject: [PATCH 3/4] Improve the test to increase code coverage --- 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 09c1d5c10ea..66c88746358 100644 --- a/pygmt/tests/test_wiggle.py +++ b/pygmt/tests/test_wiggle.py @@ -50,9 +50,9 @@ def test_wiggle_deprecate_columns_to_incols(): fig = Figure() with pytest.warns(expected_warning=FutureWarning) as record: fig.wiggle( + data, region=[-4, 4, -1, 1], projection="X8c", - data=data, columns=[1, 0, 2], scale="0.5c", color=["red+p", "gray+n"], From 040b89389cd70731d9244caefd89cfdffc743ab8 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 1 Oct 2021 08:15:38 +0800 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- pygmt/helpers/decorators.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pygmt/helpers/decorators.py b/pygmt/helpers/decorators.py index 4c47ae771bc..8eb100f1ff8 100644 --- a/pygmt/helpers/decorators.py +++ b/pygmt/helpers/decorators.py @@ -11,7 +11,6 @@ from inspect import Parameter, signature import numpy as np -import pygmt from pygmt.exceptions import GMTInvalidInput from pygmt.helpers.utils import is_nonstr_iter @@ -858,8 +857,9 @@ def new_module(*args, **kwargs): New module instance that raises a warning if positional arguments are passed. """ - # plotting function always has the "self" parameter - if len(args) > 1 and isinstance(args[0], pygmt.Figure): + # Plotting functions always have a "self" parameter + # which is a pygmt.Figure instance that has a "savefig" method + if len(args) > 1 and hasattr(args[0], "savefig"): plotting_func = 1 else: plotting_func = 0