Skip to content

Commit 5330d0a

Browse files
committed
Raise warnings when extra_arrays is used
1 parent e44e712 commit 5330d0a

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

pygmt/clib/session.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,6 +1774,7 @@ def virtualfile_in(
17741774
z=None,
17751775
required_z=False,
17761776
required_data=True,
1777+
extra_arrays=None,
17771778
):
17781779
"""
17791780
Store any data inside a virtual file.
@@ -1798,6 +1799,13 @@ def virtualfile_in(
17981799
required_data : bool
17991800
Set to True when 'data' is required, or False when dealing with
18001801
optional virtual files. [Default is True].
1802+
extra_arrays : list of 1-D arrays
1803+
Optional. A list of numpy arrays in addition to x, y, and z. All of these
1804+
arrays must be of the same size as the x/y/z arrays.
1805+
1806+
.. deprecated:: v0.16.0
1807+
The parameter 'extra_arrays' will be removed in v0.20.0. Prepare and pass
1808+
a dictionary of arrays instead. E.g., `{"x": x, "y": y, "size": size}`.
18011809
18021810
Returns
18031811
-------
@@ -1875,6 +1883,14 @@ def virtualfile_in(
18751883
_data = [x, y]
18761884
if z is not None:
18771885
_data.append(z)
1886+
if extra_arrays:
1887+
msg = (
1888+
"The parameter 'extra_arrays' will be removed in v0.20.0. "
1889+
"Prepare and pass a dictionary of arrays instead. E.g., "
1890+
"`{'x': x, 'y': y, 'size': size}`."
1891+
)
1892+
warnings.warn(message=msg, category=FutureWarning, stacklevel=1)
1893+
_data.extend(extra_arrays)
18781894
case "vectors":
18791895
if hasattr(data, "items") and not hasattr(data, "to_frame"):
18801896
# Dictionary, pandas.DataFrame or xarray.Dataset types.

pygmt/tests/test_clib_virtualfile_in.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,31 @@ def test_virtualfile_in_matrix_string_dtype():
128128
assert output == "347.5 348.5 -30.5 -30\n"
129129
# Should check that lib.virtualfile_from_vectors is called once,
130130
# not lib.virtualfile_from_matrix, but it's technically complicated.
131+
132+
133+
def test_virtualfile_in_extra_arrays(data):
134+
"""
135+
Test that the extra_arrays parameter is deprecated.
136+
"""
137+
with clib.Session() as lib:
138+
# Call the method twice to ensure only one statement in the with block.
139+
# Test that a FutureWarning is raised when extra_arrays is used.
140+
with pytest.warns(FutureWarning):
141+
with lib.virtualfile_in(
142+
check_kind="vector",
143+
x=data[:, 0],
144+
y=data[:, 1],
145+
extra_arrays=[data[:, 2]],
146+
) as vfile:
147+
pass
148+
# Test that the output is correct.
149+
with GMTTempFile() as outfile:
150+
with lib.virtualfile_in(
151+
check_kind="vector",
152+
x=data[:, 0],
153+
y=data[:, 1],
154+
extra_arrays=[data[:, 2]],
155+
) as vfile:
156+
lib.call_module("info", [vfile, "-C", f"->{outfile.name}"])
157+
output = outfile.read(keep_tabs=False)
158+
assert output == "11.5309 61.7074 -2.9289 7.8648 0.1412 0.9338\n"

0 commit comments

Comments
 (0)