Skip to content

Commit 25febab

Browse files
authored
is_nonstr_iter: 0-D array is now recognized as non-iterable (#4004)
1 parent d2d321d commit 25febab

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

pygmt/helpers/utils.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,8 @@ def build_arg_list( # noqa: PLR0912
604604

605605
def is_nonstr_iter(value: Any) -> bool:
606606
"""
607-
Check if the value is iterable (e.g., list, tuple, array) but not a string.
607+
Check if the value is iterable (e.g., list, tuple, array) but not a string or a 0-D
608+
array.
608609
609610
Parameters
610611
----------
@@ -633,8 +634,14 @@ def is_nonstr_iter(value: Any) -> bool:
633634
True
634635
>>> is_nonstr_iter(np.array(["abc", "def", "ghi"]))
635636
True
637+
>>> is_nonstr_iter(np.array(42))
638+
False
636639
"""
637-
return isinstance(value, Iterable) and not isinstance(value, str)
640+
return (
641+
isinstance(value, Iterable)
642+
and not isinstance(value, str)
643+
and not (hasattr(value, "ndim") and value.ndim == 0)
644+
)
638645

639646

640647
def launch_external_viewer(fname: PathLike, waiting: float = 0) -> None:

0 commit comments

Comments
 (0)