Skip to content

Commit ce57c59

Browse files
committed
Check if a dict of vectors contain None
1 parent df88e02 commit ce57c59

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pygmt/helpers/utils.py

Lines changed: 11 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,15 @@ 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+
if len(arrays) < 2 or any(v is None for v in arrays[:2]): # Check x/y
151+
msg = "Must provide x and y."
152+
raise GMTInvalidInput(msg)
153+
if required_z and (len(arrays) < 3 or arrays[2] is None): # Check z
154+
msg = "Must provide x, y, and z."
155+
raise GMTInvalidInput(msg)
146156

147157

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

0 commit comments

Comments
 (0)