Skip to content

Commit 33fadc3

Browse files
seismanweiji14
andauthored
Session.virtualfile_in: Deprecate parameter 'required_data' to 'required' (will be removed in v0.20.0) (#3931)
Co-authored-by: Wei Ji <[email protected]>
1 parent d8ae271 commit 33fadc3

File tree

9 files changed

+28
-21
lines changed

9 files changed

+28
-21
lines changed

pygmt/clib/session.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from pygmt.helpers import (
2929
_validate_data_input,
3030
data_kind,
31+
deprecate_parameter,
3132
tempfile_from_geojson,
3233
tempfile_from_image,
3334
)
@@ -1750,15 +1751,19 @@ def virtualfile_from_stringio(
17501751

17511752
# TODO(PyGMT>=0.20.0): Remove the deprecated parameter 'required_z'.
17521753
# TODO(PyGMT>=0.20.0): Remove the deprecated parameter 'extra_arrays'.
1754+
# TODO(PyGMT>=0.20.0): Remove the deprecated parameter 'required_data'.
1755+
@deprecate_parameter(
1756+
"required_data", "required", "v0.16.0", remove_version="v0.20.0"
1757+
)
17531758
def virtualfile_in( # noqa: PLR0912
17541759
self,
17551760
check_kind=None,
17561761
data=None,
17571762
x=None,
17581763
y=None,
17591764
z=None,
1765+
required=True,
17601766
mincols=2,
1761-
required_data=True,
17621767
required_z=False,
17631768
extra_arrays=None,
17641769
):
@@ -1780,12 +1785,16 @@ def virtualfile_in( # noqa: PLR0912
17801785
data input.
17811786
x/y/z : 1-D arrays or None
17821787
x, y, and z columns as numpy arrays.
1788+
required : bool
1789+
Set to True when 'data' or ('x' and 'y') is required. Set to False when
1790+
dealing with optional virtual files. Default is True.
1791+
1792+
.. versionchanged:: v0.16.0
1793+
The parameter 'required_data' is renamed to 'required'. The parameter
1794+
'required_data' is deprecated in v0.16.0 and will be removed in v0.20.0.
17831795
mincols
17841796
Number of minimum required columns. Default is 2 (i.e. require x and y
17851797
columns).
1786-
required_data : bool
1787-
Set to True when 'data' is required, or False when dealing with
1788-
optional virtual files. [Default is True].
17891798
required_z : bool
17901799
State whether the 'z' column is required.
17911800
@@ -1838,19 +1847,19 @@ def virtualfile_in( # noqa: PLR0912
18381847
)
18391848
mincols = 3
18401849

1841-
kind = data_kind(data, required=required_data)
1850+
kind = data_kind(data, required=required)
18421851
_validate_data_input(
18431852
data=data,
18441853
x=x,
18451854
y=y,
18461855
z=z,
1856+
required=required,
18471857
mincols=mincols,
1848-
required_data=required_data,
18491858
kind=kind,
18501859
)
18511860

18521861
if check_kind:
1853-
valid_kinds = ("file", "arg") if required_data is False else ("file",)
1862+
valid_kinds = ("file", "arg") if required is False else ("file",)
18541863
if check_kind == "raster":
18551864
valid_kinds += ("grid", "image")
18561865
elif check_kind == "vector":

pygmt/helpers/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444

4545
def _validate_data_input( # noqa: PLR0912
46-
data=None, x=None, y=None, z=None, mincols=2, required_data=True, kind=None
46+
data=None, x=None, y=None, z=None, required=True, mincols=2, kind=None
4747
) -> None:
4848
"""
4949
Check if the combination of data/x/y/z is valid.
@@ -53,7 +53,7 @@ def _validate_data_input( # noqa: PLR0912
5353
>>> _validate_data_input(data="infile")
5454
>>> _validate_data_input(x=[1, 2, 3], y=[4, 5, 6])
5555
>>> _validate_data_input(x=[1, 2, 3], y=[4, 5, 6], z=[7, 8, 9])
56-
>>> _validate_data_input(data=None, required_data=False)
56+
>>> _validate_data_input(data=None, required=False)
5757
>>> _validate_data_input()
5858
Traceback (most recent call last):
5959
...
@@ -119,7 +119,7 @@ def _validate_data_input( # noqa: PLR0912
119119
required_z = mincols >= 3
120120
if data is None: # data is None
121121
if x is None and y is None: # both x and y are None
122-
if required_data: # data is not optional
122+
if required: # data is not optional
123123
msg = "No input data provided."
124124
raise GMTInvalidInput(msg)
125125
elif x is None or y is None: # either x or y is None

pygmt/src/grdfill.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def grdfill(
225225
# Fill mode.
226226
with (
227227
lib.virtualfile_in(
228-
check_kind="raster", data=gridfill, required_data=False
228+
check_kind="raster", data=gridfill, required=False
229229
) as vbggrd,
230230
lib.virtualfile_out(kind="grid", fname=outgrid) as voutgrd,
231231
):

pygmt/src/grdimage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def grdimage(self, grid: PathLike | xr.DataArray, **kwargs):
170170
with (
171171
lib.virtualfile_in(check_kind="raster", data=grid) as vingrd,
172172
lib.virtualfile_in(
173-
check_kind="raster", data=kwargs.get("I"), required_data=False
173+
check_kind="raster", data=kwargs.get("I"), required=False
174174
) as vshadegrid,
175175
):
176176
kwargs["I"] = vshadegrid

pygmt/src/grdtrack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def grdtrack(
313313
with (
314314
lib.virtualfile_in(check_kind="raster", data=grid) as vingrd,
315315
lib.virtualfile_in(
316-
check_kind="vector", data=points, required_data=False
316+
check_kind="vector", data=points, required=False
317317
) as vintbl,
318318
lib.virtualfile_out(kind="dataset", fname=outfile) as vouttbl,
319319
):

pygmt/src/grdview.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def grdview(self, grid: PathLike | xr.DataArray, **kwargs):
145145
with (
146146
lib.virtualfile_in(check_kind="raster", data=grid) as vingrd,
147147
lib.virtualfile_in(
148-
check_kind="raster", data=kwargs.get("G"), required_data=False
148+
check_kind="raster", data=kwargs.get("G"), required=False
149149
) as vdrapegrid,
150150
):
151151
kwargs["G"] = vdrapegrid

pygmt/src/legend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,5 @@ def legend(
9898
raise GMTInvalidInput(msg)
9999

100100
with Session() as lib:
101-
with lib.virtualfile_in(data=spec, required_data=False) as vintbl:
101+
with lib.virtualfile_in(data=spec, required=False) as vintbl:
102102
lib.call_module(module="legend", args=build_arg_list(kwargs, infile=vintbl))

pygmt/src/project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def project(
247247
y=y,
248248
z=z,
249249
mincols=2,
250-
required_data=False,
250+
required=False,
251251
) as vintbl,
252252
lib.virtualfile_out(kind="dataset", fname=outfile) as vouttbl,
253253
):

pygmt/src/text.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ def text_( # noqa: PLR0912
190190
msg = "Provide either 'textfiles', 'x'/'y'/'text', or 'position'/'text'."
191191
raise GMTInvalidInput(msg)
192192

193-
required_data = position is None
194-
kind = data_kind(textfiles, required=required_data)
193+
data_is_required = position is None
194+
kind = data_kind(textfiles, required=data_is_required)
195195

196196
if position is not None and (text is None or is_nonstr_iter(text)):
197197
msg = "'text' can't be None or array when 'position' is given."
@@ -261,9 +261,7 @@ def text_( # noqa: PLR0912
261261

262262
with Session() as lib:
263263
with lib.virtualfile_in(
264-
check_kind="vector",
265-
data=textfiles or data,
266-
required_data=required_data,
264+
check_kind="vector", data=textfiles or data, required=data_is_required
267265
) as vintbl:
268266
lib.call_module(
269267
module="text",

0 commit comments

Comments
 (0)