Skip to content

Commit 528cf2a

Browse files
authored
Figure: Deprecate the private _preprocess method (will be removed in v0.18.0) (#3948)
1 parent a917dad commit 528cf2a

29 files changed

+37
-30
lines changed

pygmt/figure.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import base64
66
import os
7+
import warnings
78
from pathlib import Path
89
from tempfile import TemporaryDirectory
910
from typing import Literal, overload
@@ -119,12 +120,19 @@ def _activate_figure(self) -> None:
119120
with Session() as lib:
120121
lib.call_module(module="figure", args=[self._name, fmt])
121122

123+
# TODO(PyGMT>=v0.18.0): Remove the _preprocess method.
122124
def _preprocess(self, **kwargs):
123125
"""
124126
Call the ``figure`` module before each plotting command to ensure we're plotting
125127
to this particular figure.
126128
"""
127129
self._activate_figure()
130+
warnings.warn(
131+
"The Figure._preprocess() method is deprecated since v0.16.0 and will be "
132+
"removed in v0.18.0. Use Figure._activate_figure() instead.",
133+
FutureWarning,
134+
stacklevel=2,
135+
)
128136
return kwargs
129137

130138
@property

pygmt/src/basemap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,6 @@ def basemap(self, **kwargs):
8282
{perspective}
8383
{transparency}
8484
"""
85-
kwargs = self._preprocess(**kwargs)
85+
self._activate_figure()
8686
with Session() as lib:
8787
lib.call_module(module="basemap", args=build_arg_list(kwargs))

pygmt/src/coast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def coast(self, **kwargs):
193193
>>> # Show the plot
194194
>>> fig.show()
195195
"""
196-
kwargs = self._preprocess(**kwargs)
196+
self._activate_figure()
197197
if not args_in_kwargs(args=["C", "G", "S", "I", "N", "E", "Q", "W"], kwargs=kwargs):
198198
msg = (
199199
"At least one of the following parameters must be specified: "

pygmt/src/colorbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,6 @@ def colorbar(self, **kwargs):
144144
>>> # Show the plot
145145
>>> fig.show()
146146
"""
147-
kwargs = self._preprocess(**kwargs)
147+
self._activate_figure()
148148
with Session() as lib:
149149
lib.call_module(module="colorbar", args=build_arg_list(kwargs))

pygmt/src/contour.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def contour(
133133
{perspective}
134134
{transparency}
135135
"""
136-
kwargs = self._preprocess(**kwargs)
136+
self._activate_figure()
137137

138138
# Specify levels for contours or annotations.
139139
# One level is converted to a string with a trailing comma to separate it from

pygmt/src/grdcontour.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def grdcontour(self, grid: PathLike | xr.DataArray, **kwargs):
138138
>>> # Show the plot
139139
>>> fig.show()
140140
"""
141-
kwargs = self._preprocess(**kwargs)
141+
self._activate_figure()
142142

143143
# Specify levels for the annotation and levels parameters.
144144
# One level is converted to a string with a trailing comma to separate it from

pygmt/src/grdimage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def grdimage(self, grid: PathLike | xr.DataArray, **kwargs):
156156
>>> # show the plot
157157
>>> fig.show()
158158
"""
159-
kwargs = self._preprocess(**kwargs)
159+
self._activate_figure()
160160

161161
# Do not support -A option
162162
if any(kwargs.get(arg) is not None for arg in ["A", "img_out"]):

pygmt/src/grdview.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def grdview(self, grid: PathLike | xr.DataArray, **kwargs):
140140
>>> # Show the plot
141141
>>> fig.show()
142142
"""
143-
kwargs = self._preprocess(**kwargs)
143+
self._activate_figure()
144144
with Session() as lib:
145145
with (
146146
lib.virtualfile_in(check_kind="raster", data=grid) as vingrd,

pygmt/src/histogram.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def histogram(self, data: PathLike | TableLike, **kwargs):
135135
{transparency}
136136
{wrap}
137137
"""
138-
kwargs = self._preprocess(**kwargs)
138+
self._activate_figure()
139139
with Session() as lib:
140140
with lib.virtualfile_in(check_kind="vector", data=data) as vintbl:
141141
lib.call_module(

pygmt/src/hlines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def hlines(
8080
>>> fig.legend()
8181
>>> fig.show()
8282
"""
83-
self._preprocess()
83+
self._activate_figure()
8484

8585
# Determine the x limits from the current plot region if not specified.
8686
if xmin is None or xmax is None:

0 commit comments

Comments
 (0)