Skip to content

clib.Session: Remove deprecated virtualfile_from_data method, use virtualfile_in instead (Deprecated since v0.13.0) #3739

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion doc/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ Low level access (these are mostly used by the :mod:`pygmt.clib` package):
clib.Session.read_virtualfile
clib.Session.extract_region
clib.Session.get_libgmt_func
clib.Session.virtualfile_from_data
clib.Session.virtualfile_from_grid
clib.Session.virtualfile_from_stringio
clib.Session.virtualfile_from_matrix
Expand Down
37 changes: 0 additions & 37 deletions pygmt/clib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1920,43 +1920,6 @@ def virtualfile_in(
file_context = _virtualfile_from(_data)
return file_context

# TODO(PyGMT>=0.15.0): Remove the deprecated virtualfile_from_data method.
def virtualfile_from_data(
self,
check_kind=None,
data=None,
x=None,
y=None,
z=None,
extra_arrays=None,
required_z=False,
required_data=True,
):
"""
Store any data inside a virtual file.

.. deprecated: 0.13.0

Will be removed in v0.15.0. Use :meth:`pygmt.clib.Session.virtualfile_in`
instead.
"""
msg = (
"API function 'Session.virtualfile_from_data()' has been deprecated since "
"v0.13.0 and will be removed in v0.15.0. Use 'Session.virtualfile_in()' "
"instead."
)
warnings.warn(msg, category=FutureWarning, stacklevel=2)
return self.virtualfile_in(
check_kind=check_kind,
data=data,
x=x,
y=y,
z=z,
extra_arrays=extra_arrays,
required_z=required_z,
required_data=required_data,
)

@contextlib.contextmanager
def virtualfile_out(
self,
Expand Down
32 changes: 0 additions & 32 deletions pygmt/tests/test_clib_virtualfile_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,35 +128,3 @@ def test_virtualfile_in_matrix_string_dtype():
assert output == "347.5 348.5 -30.5 -30\n"
# Should check that lib.virtualfile_from_vectors is called once,
# not lib.virtualfile_from_matrix, but it's technically complicated.


# TODO(PyGMT>=0.16.0): Remove this test in PyGMT v0.16.0 in which the old usage of
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a typo in #3722. This test should be removed in PyGMT v0.15.0, not PyGMT v0.16.0.

# virtualfile_from_data is removed.
def test_virtualfile_from_data():
"""
Test the backwards compatibility of the virtualfile_from_data method.

This test is the same as test_virtualfile_in_required_z_matrix, but using the
deprecated method.
"""
shape = (5, 3)
dataframe = pd.DataFrame(
data=np.arange(shape[0] * shape[1]).reshape(shape), columns=["x", "y", "z"]
)
data = np.array(dataframe)
with clib.Session() as lib:
with pytest.warns(FutureWarning, match="virtualfile_from_data"):
with lib.virtualfile_from_data(
data=data, required_z=True, check_kind="vector"
) as vfile:
with GMTTempFile() as outfile:
lib.call_module("info", [vfile, f"->{outfile.name}"])
output = outfile.read(keep_tabs=True)
bounds = "\t".join(
[
f"<{i.min():.0f}/{i.max():.0f}>"
for i in (dataframe.x, dataframe.y, dataframe.z)
]
)
expected = f"<matrix memory>: N = {shape[0]}\t{bounds}\n"
assert output == expected
Loading