@@ -187,31 +187,30 @@ def _check_encoding(
187187 return "ISOLatin1+"
188188
189189
190- def data_kind (
190+ def data_kind ( # noqa: PLR0911
191191 data : Any , required : bool = True
192- ) -> Literal ["arg" , "file" , "geojson" , "grid" , "image" , "matrix" , "vectors" ]:
192+ ) -> Literal ["none" , " arg" , "file" , "geojson" , "grid" , "image" , "matrix" , "vectors" ]:
193193 """
194194 Check the kind of data that is provided to a module.
195195
196196 Recognized data kinds are:
197197
198- - ``"arg"``: bool, int or float, representing an optional argument, mainly used for
199- dealing with optional virtual files
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
200203 - ``"file"``: a string or a :class:`pathlib.PurePath` object or a sequence of them,
201204 representing a file name or a list of file names
202205 - ``"geojson"``: a geo-like Python object that implements ``__geo_interface__``
203206 (e.g., geopandas.GeoDataFrame or shapely.geometry)
204207 - ``"grid"``: a :class:`xarray.DataArray` object with dimensions not equal to 3
205208 - ``"image"``: a :class:`xarray.DataArray` object with 3 dimensions
206- - ``"matrix"``: a :class:`pandas.DataFrame` object, a 2-D :class:`numpy.ndarray`,
207- a dictionary with array-like values, or a sequence of sequences
209+ - ``"matrix"``: a 2-D :class:`numpy.ndarray` object
210+ - ``"vectors"``: a :class:`pandas.DataFrame` object, a dictionary with array-like
211+ values, or a sequence of sequences
208212
209- In addition, the data can be given via a series of vectors (e.g., x/y/z). In this
210- case, the ``data`` argument is ``None`` and the data kind is determined by the
211- ``required`` argument. The data kind is ``"vectors"`` if ``required`` is ``True``,
212- otherwise the data kind is ``"arg"``.
213-
214- The function will fallback to ``"matrix"`` for any unrecognized data.
213+ The function will fallback to ``"vectors"`` for any unrecognized data.
215214
216215 Parameters
217216 ----------
@@ -232,12 +231,12 @@ def data_kind(
232231 >>> import xarray as xr
233232 >>> import pandas as pd
234233 >>> import pathlib
235- >>> [data_kind(data=data) for data in (2, 2.0, True, False)]
236- ['arg', 'arg', 'arg', 'arg']
237234 >>> data_kind(data=None)
238- 'vectors '
235+ 'none '
239236 >>> data_kind(data=None, required=False)
240237 'arg'
238+ >>> [data_kind(data=data) for data in (2, 2.0, True, False)]
239+ ['arg', 'arg', 'arg', 'arg']
241240 >>> data_kind(data="my-data-file.txt")
242241 'file'
243242 >>> data_kind(data=pathlib.Path("my-data-file.txt"))
@@ -251,16 +250,16 @@ def data_kind(
251250 >>> data_kind(data=np.arange(10).reshape((5, 2)))
252251 'matrix'
253252 >>> data_kind(data=pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]}))
254- 'matrix '
253+ 'vectors '
255254 >>> data_kind(data={"x": [1, 2], "y": [3, 4]})
256- 'matrix '
255+ 'vectors '
257256 >>> data_kind(data=[1, 2, 3])
258- 'matrix '
257+ 'vectors '
259258 """
260259 # data is None, so data must be given via a series of vectors (i.e., x/y/z).
261260 # The only exception is when dealing with optional virtual files.
262261 if data is None :
263- return "vectors " if required else "arg"
262+ return "none " if required else "arg"
264263
265264 # A file or a list of files
266265 if isinstance (data , str | pathlib .PurePath ) or (
@@ -282,8 +281,12 @@ def data_kind(
282281 if hasattr (data , "__geo_interface__" ):
283282 return "geojson"
284283
285- # Fallback to "matrix" for anything else
286- return "matrix"
284+ # A 2-D numpy.ndarray
285+ if hasattr (data , "__array_interface__" ) and data .ndim == 2 :
286+ return "matrix"
287+
288+ # Fallback to "vectors" for anything else
289+ return "vectors"
287290
288291
289292def non_ascii_to_octal (
0 commit comments