Skip to content

Commit ab18175

Browse files
committed
Refactor to check kind in data_kind function
1 parent 7cfba73 commit ab18175

File tree

7 files changed

+12
-15
lines changed

7 files changed

+12
-15
lines changed

pygmt/src/grdcut.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def grdcut(
117117
raise GMTInvalidInput(msg)
118118

119119
# Determine the output data kind based on the input data kind.
120-
match inkind := data_kind(grid):
120+
match inkind := data_kind(grid, check_kind="raster"):
121121
case "grid" | "image":
122122
outkind = inkind
123123
case "file":
@@ -128,7 +128,7 @@ def grdcut(
128128

129129
with Session() as lib:
130130
with (
131-
lib.virtualfile_in(check_kind="raster", data=grid) as vingrd,
131+
lib.virtualfile_in(data=grid) as vingrd,
132132
lib.virtualfile_out(kind=outkind, fname=outgrid) as voutgrd,
133133
):
134134
kwargs["G"] = voutgrd

pygmt/src/legend.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,7 @@ def legend(
8989
if kwargs.get("F") is None:
9090
kwargs["F"] = box
9191

92-
kind = data_kind(spec)
93-
if kind not in {"empty", "file", "stringio"}:
94-
msg = f"Unrecognized data type: {type(spec)}"
95-
raise GMTInvalidInput(msg)
92+
kind = data_kind(spec, check_kind=("empty", "file", "stringio"))
9693
if kind == "file" and is_nonstr_iter(spec):
9794
msg = "Only one legend specification file is allowed."
9895
raise GMTInvalidInput(msg)

pygmt/src/meca.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def _preprocess_spec(spec, colnames, override_cols):
4949
Dictionary of column names and values to override in the input data. Only makes
5050
sense if ``spec`` is a dict or :class:`pandas.DataFrame`.
5151
"""
52-
kind = data_kind(spec) # Determine the kind of the input data.
52+
kind = data_kind(spec, check_kind="vector") # Determine the kind of the input data.
5353

5454
# Convert pandas.DataFrame and numpy.ndarray to dict.
5555
if isinstance(spec, pd.DataFrame):
@@ -359,5 +359,5 @@ def meca( # noqa: PLR0913
359359
kwargs["A"] = _auto_offset(spec)
360360
kwargs["S"] = f"{_convention.code}{scale}"
361361
with Session() as lib:
362-
with lib.virtualfile_in(check_kind="vector", data=spec) as vintbl:
362+
with lib.virtualfile_in(data=spec) as vintbl:
363363
lib.call_module(module="meca", args=build_arg_list(kwargs, infile=vintbl))

pygmt/src/plot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def plot( # noqa: PLR0912
232232
# parameter.
233233
self._activate_figure()
234234

235-
kind = data_kind(data)
235+
kind = data_kind(data, check_kind="vector")
236236
if kind == "empty": # Data is given via a series of vectors.
237237
data = {"x": x, "y": y}
238238
# Parameters for vector styles
@@ -280,5 +280,5 @@ def plot( # noqa: PLR0912
280280
kwargs["S"] = "s0.2c"
281281

282282
with Session() as lib:
283-
with lib.virtualfile_in(check_kind="vector", data=data) as vintbl:
283+
with lib.virtualfile_in(data=data) as vintbl:
284284
lib.call_module(module="plot", args=build_arg_list(kwargs, infile=vintbl))

pygmt/src/plot3d.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def plot3d( # noqa: PLR0912
210210
# parameter.
211211
self._activate_figure()
212212

213-
kind = data_kind(data)
213+
kind = data_kind(data, check_kind="vector")
214214
if kind == "empty": # Data is given via a series of vectors.
215215
data = {"x": x, "y": y, "z": z}
216216
# Parameters for vector styles
@@ -259,5 +259,5 @@ def plot3d( # noqa: PLR0912
259259
kwargs["S"] = "u0.2c"
260260

261261
with Session() as lib:
262-
with lib.virtualfile_in(check_kind="vector", data=data, mincols=3) as vintbl:
262+
with lib.virtualfile_in(data=data, mincols=3) as vintbl:
263263
lib.call_module(module="plot3d", args=build_arg_list(kwargs, infile=vintbl))

pygmt/src/text.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def text_( # noqa: PLR0912
191191
raise GMTInvalidInput(msg)
192192

193193
data_is_required = position is None
194-
kind = data_kind(textfiles, required=data_is_required)
194+
kind = data_kind(textfiles, required=data_is_required, check_kind="vector")
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,7 +261,7 @@ def text_( # noqa: PLR0912
261261

262262
with Session() as lib:
263263
with lib.virtualfile_in(
264-
check_kind="vector", data=textfiles or data, required=data_is_required
264+
data=textfiles or data, required=data_is_required
265265
) as vintbl:
266266
lib.call_module(
267267
module="text",

pygmt/src/x2sys_cross.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def x2sys_cross(
195195

196196
file_contexts: list[contextlib.AbstractContextManager[Any]] = []
197197
for track in tracks:
198-
match data_kind(track):
198+
match data_kind(track, check_kind="vector"):
199199
case "file":
200200
file_contexts.append(contextlib.nullcontext(track))
201201
case "vectors":

0 commit comments

Comments
 (0)