Skip to content

Commit

Permalink
blockm/contour/plot/plot3d/rose/surface/wiggle: Change the parameter …
Browse files Browse the repository at this point in the history
…order of data array and input arrays (GenericMappingTools#1978)
  • Loading branch information
seisman authored and Josh Sixsmith committed Dec 21, 2022
1 parent 824e215 commit 5750390
Show file tree
Hide file tree
Showing 9 changed files with 3 additions and 103 deletions.
1 change: 0 additions & 1 deletion pygmt/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Functions, classes, decorators, and context managers to help wrap GMT modules.
"""
from pygmt.helpers.decorators import (
check_data_input_order,
deprecate_parameter,
fmt_docstring,
kwargs_to_strings,
Expand Down
68 changes: 0 additions & 68 deletions pygmt/helpers/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,71 +806,3 @@ def new_module(*args, **kwargs):
return new_module

return deprecator


def check_data_input_order(deprecate_version, remove_version):
"""
Decorator to raise a FutureWarning if the order of data input parameters
changes and positional arguments are passed.
The decorator is temporary and should be removed in v0.7.0.
Parameters
----------
deprecate_version : str
The PyGMT version when the order of data input parameters is changed.
remove_version : str
The PyGMT version when the deprecation warning should be removed.
Examples
--------
>>> @check_data_input_order("v0.0.0", "v9.9.9")
... def module(data=None, x=None, y=None, z=None, **kwargs):
... "A module that prints the arguments it received"
... print(f"data={data}, x={x}, y={y}, z={z}")
>>> module(data="table.txt")
data=table.txt, x=None, y=None, z=None
>>> module(x=0, y=1, z=2)
data=None, x=0, y=1, z=2
>>> with warnings.catch_warnings(record=True) as w:
... module(0, 1, 2)
... assert len(w) == 1
... assert issubclass(w[0].category, FutureWarning)
...
data=0, x=1, y=2, z=None
"""

def data_input_order_checker(module_func):
"""
The decorator that creates the new function to check if positional
arguments are passed.
"""

@functools.wraps(module_func)
def new_module(*args, **kwargs):
"""
New module instance that raises a warning if positional arguments
are passed.
"""
# 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

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. "
"You can silence the warning by passing keyword arguments "
"like 'x=x, y=y, z=z'. Otherwise, the warning will be removed "
f"in {remove_version}."
)
warnings.warn(msg, category=FutureWarning, stacklevel=2)
return module_func(*args, **kwargs)

return new_module

return data_input_order_checker
4 changes: 0 additions & 4 deletions pygmt/src/blockm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from pygmt.helpers import (
GMTTempFile,
build_arg_string,
check_data_input_order,
fmt_docstring,
kwargs_to_strings,
use_alias,
Expand Down Expand Up @@ -70,7 +69,6 @@ def _blockm(block_method, data, x, y, z, outfile, **kwargs):


@fmt_docstring
@check_data_input_order("v0.5.0", remove_version="v0.7.0")
@use_alias(
I="spacing",
R="region",
Expand Down Expand Up @@ -168,7 +166,6 @@ def blockmean(data=None, x=None, y=None, z=None, outfile=None, **kwargs):


@fmt_docstring
@check_data_input_order("v0.5.0", remove_version="v0.7.0")
@use_alias(
I="spacing",
R="region",
Expand Down Expand Up @@ -256,7 +253,6 @@ def blockmedian(data=None, x=None, y=None, z=None, outfile=None, **kwargs):


@fmt_docstring
@check_data_input_order("v0.5.0", remove_version="v0.7.0")
@use_alias(
I="spacing",
R="region",
Expand Down
9 changes: 1 addition & 8 deletions pygmt/src/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@
"""

from pygmt.clib import Session
from pygmt.helpers import (
build_arg_string,
check_data_input_order,
fmt_docstring,
kwargs_to_strings,
use_alias,
)
from pygmt.helpers import build_arg_string, fmt_docstring, kwargs_to_strings, use_alias


@fmt_docstring
@check_data_input_order("v0.5.0", remove_version="v0.7.0")
@use_alias(
A="annotation",
B="frame",
Expand Down
2 changes: 0 additions & 2 deletions pygmt/src/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers import (
build_arg_string,
check_data_input_order,
data_kind,
fmt_docstring,
is_nonstr_iter,
Expand All @@ -16,7 +15,6 @@


@fmt_docstring
@check_data_input_order("v0.5.0", remove_version="v0.7.0")
@use_alias(
A="straight_line",
B="frame",
Expand Down
2 changes: 0 additions & 2 deletions pygmt/src/plot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers import (
build_arg_string,
check_data_input_order,
data_kind,
fmt_docstring,
is_nonstr_iter,
Expand All @@ -16,7 +15,6 @@


@fmt_docstring
@check_data_input_order("v0.5.0", remove_version="v0.7.0")
@use_alias(
A="straight_line",
B="frame",
Expand Down
9 changes: 1 addition & 8 deletions pygmt/src/rose.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@
"""

from pygmt.clib import Session
from pygmt.helpers import (
build_arg_string,
check_data_input_order,
fmt_docstring,
kwargs_to_strings,
use_alias,
)
from pygmt.helpers import build_arg_string, fmt_docstring, kwargs_to_strings, use_alias


@fmt_docstring
@check_data_input_order("v0.5.0", remove_version="v0.7.0")
@use_alias(
A="sector",
B="frame",
Expand Down
2 changes: 0 additions & 2 deletions pygmt/src/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from pygmt.helpers import (
GMTTempFile,
build_arg_string,
check_data_input_order,
fmt_docstring,
kwargs_to_strings,
use_alias,
Expand All @@ -17,7 +16,6 @@


@fmt_docstring
@check_data_input_order("v0.5.0", remove_version="v0.7.0")
@use_alias(
I="spacing",
R="region",
Expand Down
9 changes: 1 addition & 8 deletions pygmt/src/wiggle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@
wiggle - Plot z=f(x,y) anomalies along tracks.
"""
from pygmt.clib import Session
from pygmt.helpers import (
build_arg_string,
check_data_input_order,
fmt_docstring,
kwargs_to_strings,
use_alias,
)
from pygmt.helpers import build_arg_string, fmt_docstring, kwargs_to_strings, use_alias


@fmt_docstring
@check_data_input_order("v0.5.0", remove_version="v0.7.0")
@use_alias(
B="frame",
D="position",
Expand Down

0 comments on commit 5750390

Please sign in to comment.