Skip to content

Commit ff86051

Browse files
committed
Session.virtualf_in: Allow passing the data kind if it's already known
1 parent ab18175 commit ff86051

File tree

6 files changed

+15
-7
lines changed

6 files changed

+15
-7
lines changed

pygmt/clib/session.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,7 @@ def virtualfile_from_stringio(
17581758
def virtualfile_in(
17591759
self,
17601760
check_kind=None,
1761+
kind=None,
17611762
data=None,
17621763
x=None,
17631764
y=None,
@@ -1847,7 +1848,9 @@ def virtualfile_in(
18471848
)
18481849
mincols = 3
18491850

1850-
kind = data_kind(data, required=required, check_kind=check_kind)
1851+
# Determine the data kind if not given.
1852+
if kind is None:
1853+
kind = data_kind(data, required=required, check_kind=check_kind)
18511854
_validate_data_input(
18521855
data=data,
18531856
x=x,

pygmt/src/grdcut.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def grdcut(
128128

129129
with Session() as lib:
130130
with (
131-
lib.virtualfile_in(data=grid) as vingrd,
131+
lib.virtualfile_in(data=grid, kind=inkind) 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,5 @@ def legend(
9595
raise GMTInvalidInput(msg)
9696

9797
with Session() as lib:
98-
with lib.virtualfile_in(data=spec, required=False) as vintbl:
98+
with lib.virtualfile_in(data=spec, required=False, kind=kind) as vintbl:
9999
lib.call_module(module="legend", args=build_arg_list(kwargs, infile=vintbl))

pygmt/src/plot.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ def plot( # noqa: PLR0912
234234

235235
kind = data_kind(data, check_kind="vector")
236236
if kind == "empty": # Data is given via a series of vectors.
237+
kind = "vectors"
237238
data = {"x": x, "y": y}
238239
# Parameters for vector styles
239240
if (
@@ -280,5 +281,5 @@ def plot( # noqa: PLR0912
280281
kwargs["S"] = "s0.2c"
281282

282283
with Session() as lib:
283-
with lib.virtualfile_in(data=data) as vintbl:
284+
with lib.virtualfile_in(data=data, kind=kind) as vintbl:
284285
lib.call_module(module="plot", args=build_arg_list(kwargs, infile=vintbl))

pygmt/src/plot3d.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ def plot3d( # noqa: PLR0912
212212

213213
kind = data_kind(data, check_kind="vector")
214214
if kind == "empty": # Data is given via a series of vectors.
215+
kind = "vectors"
215216
data = {"x": x, "y": y, "z": z}
216217
# Parameters for vector styles
217218
if (
@@ -259,5 +260,5 @@ def plot3d( # noqa: PLR0912
259260
kwargs["S"] = "u0.2c"
260261

261262
with Session() as lib:
262-
with lib.virtualfile_in(data=data, mincols=3) as vintbl:
263+
with lib.virtualfile_in(data=data, mincols=3, kind=kind) as vintbl:
263264
lib.call_module(module="plot3d", args=build_arg_list(kwargs, infile=vintbl))

pygmt/src/text.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
w="wrap",
4343
)
4444
@kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence")
45-
def text_( # noqa: PLR0912
45+
def text_( # noqa: PLR0912, PLR0915
4646
self,
4747
textfiles: PathLike | TableLike | None = None,
4848
x=None,
@@ -225,6 +225,7 @@ def text_( # noqa: PLR0912
225225
confdict = {}
226226
data = None
227227
if kind == "empty":
228+
kind = "vectors"
228229
data = {"x": x, "y": y}
229230

230231
for arg, flag, name in array_args:
@@ -261,7 +262,9 @@ def text_( # noqa: PLR0912
261262

262263
with Session() as lib:
263264
with lib.virtualfile_in(
264-
data=textfiles or data, required=data_is_required
265+
data=textfiles or data,
266+
required=data_is_required,
267+
kind=kind,
265268
) as vintbl:
266269
lib.call_module(
267270
module="text",

0 commit comments

Comments
 (0)