@@ -190,7 +190,7 @@ def _check_encoding(
190
190
def data_kind (
191
191
data : Any , required : bool = True
192
192
) -> Literal [
193
- "arg" , "file" , "geojson" , "grid" , "image" , "matrix" , "stringio" , "vectors"
193
+ "arg" , "empty" , " file" , "geojson" , "grid" , "image" , "matrix" , "stringio" , "vectors"
194
194
]:
195
195
r"""
196
196
Check the kind of data that is provided to a module.
@@ -200,6 +200,8 @@ def data_kind(
200
200
201
201
- ``"arg"``: ``data`` is ``None`` and ``required=False``, or bool, int, float,
202
202
representing an optional argument, used for dealing with optional virtual files
203
+ - ``"empty"`: ``data`` is ``None`` and ``required=True``. It means the data is given
204
+ via a series of vectors like x/y/z
203
205
- ``"file"``: a string or a :class:`pathlib.PurePath` object or a sequence of them,
204
206
representing one or more file names
205
207
- ``"geojson"``: a geo-like Python object that implements ``__geo_interface__``
@@ -209,10 +211,9 @@ def data_kind(
209
211
- ``"stringio"``: a :class:`io.StringIO` object
210
212
- ``"matrix"``: a 2-D array-like object that implements ``__array_interface__``
211
213
(e.g., :class:`numpy.ndarray`)
212
- - ``"vectors"``: ``data`` is ``None`` and ``required=True``, or any unrecognized
213
- data. Common data types include, a :class:`pandas.DataFrame` object, a dictionary
214
- with array-like values, a 1-D/3-D :class:`numpy.ndarray` object, or array-like
215
- objects.
214
+ - ``"vectors"``: any unrecognized data. Common data types include, a
215
+ :class:`pandas.DataFrame` object, a dictionary with array-like values, a 1-D/3-D
216
+ :class:`numpy.ndarray` object, or array-like objects.
216
217
217
218
Parameters
218
219
----------
@@ -242,6 +243,11 @@ def data_kind(
242
243
>>> data_kind(data=None, required=False)
243
244
'arg'
244
245
246
+ The "empty" kind:
247
+
248
+ >>> data_kind(data=None, required=True)
249
+ 'empty'
250
+
245
251
The "file" kind:
246
252
247
253
>>> [data_kind(data=data) for data in ("file.txt", ("file1.txt", "file2.txt"))]
@@ -293,10 +299,10 @@ def data_kind(
293
299
'vectors'
294
300
>>> data_kind(data=pd.Series([1, 2, 3], name="x")) # pd.Series
295
301
'vectors'
296
- >>> data_kind(data=None)
297
- 'vectors'
298
302
"""
299
303
match data :
304
+ case None if required : # No data provided and required=True.
305
+ kind = "empty"
300
306
case str () | pathlib .PurePath (): # One file.
301
307
kind = "file"
302
308
case list () | tuple () if all (
0 commit comments