|
14 | 14 | from collections.abc import Iterable, Mapping, Sequence
|
15 | 15 | from typing import Any, Literal
|
16 | 16 |
|
17 |
| -import numpy as np |
18 | 17 | import xarray as xr
|
19 | 18 | from pygmt.encodings import charset
|
20 | 19 | from pygmt.exceptions import GMTInvalidInput
|
@@ -208,7 +207,8 @@ def data_kind(
|
208 | 207 | - ``"grid"``: a :class:`xarray.DataArray` object that is not 3-D
|
209 | 208 | - ``"image"``: a 3-D :class:`xarray.DataArray` object
|
210 | 209 | - ``"stringio"``: a :class:`io.StringIO` object
|
211 |
| - - ``"matrix"``: a 2-D :class:`numpy.ndarray` object |
| 210 | + - ``"matrix"``: a 2-D array-like object that implements ``__array_interface__`` |
| 211 | + (e.g., :class:`numpy.ndarray`) |
212 | 212 | - ``"vectors"``: ``data`` is ``None`` and ``required=True``, or any unrecognized
|
213 | 213 | data. Common data types include, a :class:`pandas.DataFrame` object, a dictionary
|
214 | 214 | with array-like values, a 1-D/3-D :class:`numpy.ndarray` object, or array-like
|
@@ -316,7 +316,10 @@ def data_kind(
|
316 | 316 | # geopandas.GeoDataFrame or shapely.geometry).
|
317 | 317 | # Reference: https://gist.github.com/sgillies/2217756
|
318 | 318 | kind = "geojson"
|
319 |
| - case np.ndarray() if data.ndim == 2: # A 2-D numpy.ndarray object. |
| 319 | + case x if hasattr(x, "__array_interface__") and data.ndim == 2: |
| 320 | + # 2-D Array-like objects that implements ``__array_interface__`` (e.g., |
| 321 | + # numpy.ndarray). |
| 322 | + # Reference: https://numpy.org/doc/stable/reference/arrays.interface.html |
320 | 323 | kind = "matrix"
|
321 | 324 | case _: # Fall back to "vectors" if data is None and required=True.
|
322 | 325 | kind = "vectors"
|
|
0 commit comments