diff --git a/pygmt/clib/session.py b/pygmt/clib/session.py index d2ba0aef4ff..4ba634a6a30 100644 --- a/pygmt/clib/session.py +++ b/pygmt/clib/session.py @@ -1330,7 +1330,7 @@ def open_virtual_file(self, family, geometry, direction, data): return self.open_virtualfile(family, geometry, direction, data) @contextlib.contextmanager - def virtualfile_from_vectors(self, vectors): + def virtualfile_from_vectors(self, vectors, *args): """ Store 1-D arrays as columns of a table inside a virtual file. @@ -1379,6 +1379,17 @@ def virtualfile_from_vectors(self, vectors): ... print(fout.read().strip()) : N = 3 <1/3> <4/6> <7/9> """ + if len(args) > 0: + warnings.warn( + "Passing multiple arguments to Session.virtualfile_fro_vectors is " + "deprecated since v0.14.0 and will be unsupported in v0.16.0. " + "Pass all vectors as a single tuple instead, e.g., " + "Use `with lib.virtualfile_from_vectors((x, y, z)) as vfile` " + "instead of `with lib.virtualfile_from_vectors(x, y, z) as vfile`.", + category=FutureWarning, + stacklevel=3, + ) + vectors = (vectors, *args) # Conversion to a C-contiguous array needs to be done here and not in # put_vector or put_strings because we need to maintain a reference to # the copy while it is being used by the C API. Otherwise, the array diff --git a/pygmt/tests/test_clib_virtualfile_from_vectors.py b/pygmt/tests/test_clib_virtualfile_from_vectors.py index f212a1bcc46..18cb4053f37 100644 --- a/pygmt/tests/test_clib_virtualfile_from_vectors.py +++ b/pygmt/tests/test_clib_virtualfile_from_vectors.py @@ -170,3 +170,26 @@ def test_virtualfile_from_vectors_arraylike(): bounds = "\t".join([f"<{min(i):.0f}/{max(i):.0f}>" for i in (x, y, z)]) expected = f": N = {size}\t{bounds}\n" assert output == expected + + +def test_virtualfile_from_vectors_args(): + """ + Test the backward compatibility of the deprecated syntax for passing multiple + vectors. + + This test is the same as test_virtualfile_from_vectors_arraylike, but using the + old syntax. + """ + size = 13 + x = list(range(0, size, 1)) + y = tuple(range(size, size * 2, 1)) + z = range(size * 2, size * 3, 1) + with pytest.warns(FutureWarning, match="virtualfile_from_vectors"): + with clib.Session() as lib: + with lib.virtualfile_from_vectors(x, y, z) as vfile: + with GMTTempFile() as outfile: + lib.call_module("info", [vfile, f"->{outfile.name}"]) + output = outfile.read(keep_tabs=True) + bounds = "\t".join([f"<{min(i):.0f}/{max(i):.0f}>" for i in (x, y, z)]) + expected = f": N = {size}\t{bounds}\n" + assert output == expected