Skip to content

Commit 4a4f192

Browse files
committed
2-D array-like that implements '__array_interface__' is matrix
1 parent 51569c8 commit 4a4f192

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pygmt/helpers/utils.py

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

17-
import numpy as np
1817
import xarray as xr
1918
from pygmt.encodings import charset
2019
from pygmt.exceptions import GMTInvalidInput
@@ -208,7 +207,8 @@ def data_kind(
208207
- ``"grid"``: a :class:`xarray.DataArray` object that is not 3-D
209208
- ``"image"``: a 3-D :class:`xarray.DataArray` object
210209
- ``"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`)
212212
- ``"vectors"``: ``data`` is ``None`` and ``required=True``, or any unrecognized
213213
data. Common data types include, a :class:`pandas.DataFrame` object, a dictionary
214214
with array-like values, a 1-D/3-D :class:`numpy.ndarray` object, or array-like
@@ -316,7 +316,10 @@ def data_kind(
316316
# geopandas.GeoDataFrame or shapely.geometry).
317317
# Reference: https://gist.github.com/sgillies/2217756
318318
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
320323
kind = "matrix"
321324
case _: # Fall back to "vectors" if data is None and required=True.
322325
kind = "vectors"

0 commit comments

Comments
 (0)