Skip to content

Commit

Permalink
Figure.contour: Deprecate parameter "columns" to "incols" (remove in …
Browse files Browse the repository at this point in the history
…v0.6.0) (#1303)

* Figure.contour: Add and deprecate parameter "columns" to "incols" (remove in v0.6.0)
* add test for deprecation warning
  • Loading branch information
michaelgrund authored and seisman committed Jun 8, 2021
1 parent a29ba75 commit 477b4f2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pygmt/src/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pygmt.helpers import (
build_arg_string,
data_kind,
deprecate_parameter,
dummy_context,
fmt_docstring,
kwargs_to_strings,
Expand All @@ -15,6 +16,7 @@


@fmt_docstring
@deprecate_parameter("columns", "incols", "v0.4.0", remove_version="v0.6.0")
@use_alias(
A="annotation",
B="frame",
Expand All @@ -30,7 +32,7 @@
X="xshift",
Y="yshift",
c="panel",
i="columns",
i="incols",
l="label",
p="perspective",
t="transparency",
Expand Down Expand Up @@ -104,6 +106,7 @@ def contour(self, x=None, y=None, z=None, data=None, **kwargs):
{V}
{XY}
{c}
{i}
{p}
{t}
"""
Expand Down
34 changes: 34 additions & 0 deletions pygmt/tests/test_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,37 @@ def test_contour_from_file(region):
data=POINTS_DATA, projection="X10c", region=region, frame="af", pen="#ffcb87"
)
return fig


@pytest.mark.mpl_image_compare(filename="test_contour_vec.png")
def test_contour_deprecate_columns_to_incols(region):
"""
Make sure that the old parameter "columns" is supported and it reports an
warning.
Modified from the test_contour_vec() test.
"""
fig = Figure()
x, y = np.meshgrid(
np.linspace(region[0], region[1]), np.linspace(region[2], region[3])
)
x = x.flatten()
y = y.flatten()
z = (x - 0.5 * (region[0] + region[1])) ** 2 + 4 * y ** 2
z = np.exp(-z / 10 ** 2 * np.log(2))

# generate dataframe
# switch x and y from here onwards to simulate different column order
data = np.array([y, x, z]).T

with pytest.warns(expected_warning=FutureWarning) as record:
fig.contour(
data=data,
projection="X10c",
region=region,
frame="a",
pen=True,
columns=[1, 0, 2],
)
assert len(record) == 1 # check that only one warning was raised
return fig

0 comments on commit 477b4f2

Please sign in to comment.