Skip to content

Commit ad6b015

Browse files
committed
Ensure x/y are not None for dictionary input
1 parent 7e46181 commit ad6b015

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pygmt/helpers/utils.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import time
1313
import webbrowser
1414
from collections.abc import Iterable, Mapping, Sequence
15+
from itertools import islice
1516
from pathlib import Path
1617
from typing import Any, Literal
1718

@@ -41,7 +42,7 @@
4142
]
4243

4344

44-
def _validate_data_input(
45+
def _validate_data_input( # noqa: PLR0912
4546
data=None, x=None, y=None, z=None, required_z=False, required_data=True, kind=None
4647
) -> None:
4748
"""
@@ -143,6 +144,16 @@ def _validate_data_input(
143144
raise GMTInvalidInput(msg)
144145
if hasattr(data, "data_vars") and len(data.data_vars) < 3: # xr.Dataset
145146
raise GMTInvalidInput(msg)
147+
if kind == "vectors" and isinstance(data, dict):
148+
# Iterator over the up-to-3 first elements.
149+
arrays = list(islice(data.values(), 3))
150+
# A dictionary holding multiple columns
151+
if len(arrays) < 2 or any(v is None for v in arrays[:2]): # Check x/y
152+
msg = "Must provide both x and y."
153+
raise GMTInvalidInput(msg)
154+
if required_z and (len(arrays) < 3 or arrays[3] is None):
155+
msg = "Must provide x, y, and z."
156+
raise GMTInvalidInput(msg)
146157

147158

148159
def _is_printable_ascii(argstr: str) -> bool:

0 commit comments

Comments
 (0)