Skip to content

Commit c589a40

Browse files
committed
Updates
1 parent 146e430 commit c589a40

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

pygmt/clib/session.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1634,7 +1634,10 @@ def virtualfile_from_stringio(self, stringio: io.StringIO):
16341634
>>> import io
16351635
>>> from pygmt.clib import Session
16361636
>>> stringio = io.StringIO(
1637-
... "H 24p Legend\nN 2\nS 0.1i c 0.15i p300/12 0.25p 0.3i My circle"
1637+
... "# Comment\n"
1638+
... "H 24p Legend\n"
1639+
... "N 2\n"
1640+
... "S 0.1i c 0.15i p300/12 0.25p 0.3i My circle\n"
16381641
... )
16391642
>>> with Session() as lib:
16401643
... with lib.virtualfile_from_stringio(stringio) as fin:

pygmt/helpers/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,9 @@ def data_kind(
247247
>>> data_kind(data=io.StringIO("TEXT1\nTEXT23\n"))
248248
'stringio'
249249
"""
250-
kind: Literal["arg", "file", "geojson", "grid", "image", "matrix", "vectors"]
250+
kind: Literal[
251+
"arg", "file", "geojson", "grid", "image", "matrix", "stringio", "vectors"
252+
]
251253
if isinstance(data, str | pathlib.PurePath) or (
252254
isinstance(data, list | tuple)
253255
and all(isinstance(_file, str | pathlib.PurePath) for _file in data)

pygmt/src/legend.py

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

92-
match data_kind(spec):
93-
case "vectors": # spec is None
94-
specfile = ""
95-
case kind if kind == "file" and not is_nonstr_iter(spec):
96-
specfile = spec
97-
case "stringio":
98-
specfile = spec
99-
case _:
100-
raise GMTInvalidInput(f"Unrecognized data type: {type(spec)}")
92+
kind = data_kind(spec)
93+
if kind not in {"vectors", "file", "stringio"}:
94+
raise GMTInvalidInput(f"Unrecognized data type: {type(spec)}")
95+
if kind == "file" and is_nonstr_iter(spec):
96+
raise GMTInvalidInput("Only one legend specification file is allowed.")
10197

10298
with Session() as lib:
103-
with lib.virtualfile_in(data=specfile) as vintbl:
99+
with lib.virtualfile_in(data=spec, required_data=False) as vintbl:
104100
lib.call_module(module="legend", args=build_arg_list(kwargs, infile=vintbl))

0 commit comments

Comments
 (0)