Skip to content

Commit 1367f36

Browse files
committed
data_kind: Improve comments and also add one more test
1 parent e98f74e commit 1367f36

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

pygmt/helpers/utils.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from collections.abc import Iterable, Sequence
1515
from typing import Any, Literal
1616

17+
import numpy as np
1718
import xarray as xr
1819
from pygmt.encodings import charset
1920
from pygmt.exceptions import GMTInvalidInput
@@ -195,11 +196,10 @@ def data_kind( # noqa: PLR0911
195196
196197
Recognized data kinds are:
197198
198-
- ``"none"``: None and data is required. In this case, the data is usually given via
199-
a series of vectors (e.g., x/y/z)
200-
- ``"arg"``: bool, int, float, or None (only when ``required`` is False),
201-
representing an optional argument, mainly used for dealing with optional virtual
202-
files
199+
- ``"none"``: data is ``None`` and is required. In this case, the input data is
200+
usually given via a series of vectors (e.g., x/y/z)
201+
- ``"arg"``: data is ``None`` and ``required=False``, or bool, int, float,
202+
representing an optional argument, used for dealing with optional virtual files
203203
- ``"file"``: a string or a :class:`pathlib.PurePath` object or a sequence of them,
204204
representing a file name or a list of file names
205205
- ``"geojson"``: a geo-like Python object that implements ``__geo_interface__``
@@ -253,14 +253,16 @@ def data_kind( # noqa: PLR0911
253253
'vectors'
254254
>>> data_kind(data={"x": [1, 2], "y": [3, 4]})
255255
'vectors'
256+
>>> data_kind(data=[[1, 2], [3, 4]])
257+
'vectors'
256258
>>> data_kind(data=[1, 2, 3])
257259
'vectors'
258260
"""
259261
# data is None and is required.
260262
if data is None and required:
261263
return "none"
262264

263-
# A file or a list of files
265+
# A file or a sequence of files
264266
if isinstance(data, str | pathlib.PurePath) or (
265267
isinstance(data, list | tuple)
266268
and all(isinstance(_file, str | pathlib.PurePath) for _file in data)
@@ -277,11 +279,12 @@ def data_kind( # noqa: PLR0911
277279

278280
# Geo-like Python object that implements ``__geo_interface__`` (e.g.,
279281
# geopandas.GeoDataFrame or shapely.geometry)
282+
# Reference: https://gist.github.com/sgillies/2217756
280283
if hasattr(data, "__geo_interface__"):
281284
return "geojson"
282285

283286
# A 2-D numpy.ndarray
284-
if hasattr(data, "__array_interface__") and data.ndim == 2:
287+
if isinstance(data, np.ndarray) and data.ndim == 2:
285288
return "matrix"
286289

287290
# Fallback to "vectors" for anything else

0 commit comments

Comments
 (0)