12
12
import warnings
13
13
import webbrowser
14
14
from collections .abc import Iterable , Sequence
15
- from typing import Any
15
+ from typing import Any , Literal
16
16
17
17
import xarray as xr
18
18
from pygmt .encodings import charset
@@ -115,7 +115,9 @@ def validate_data_input(
115
115
raise GMTInvalidInput ("data must provide x, y, and z columns." )
116
116
117
117
118
- def data_kind (data = None , required_data = True ):
118
+ def data_kind (
119
+ data : Any = None , required : bool = True
120
+ ) -> Literal ["arg" , "file" , "geojson" , "grid" , "image" , "matrix" , "vectors" ]:
119
121
"""
120
122
Check what kind of data is provided to a module.
121
123
@@ -137,15 +139,14 @@ def data_kind(data=None, required_data=True):
137
139
Pass in either a file name or :class:`pathlib.Path` to an ASCII data
138
140
table, an :class:`xarray.DataArray`, a 1-D/2-D
139
141
{table-classes} or an option argument.
140
- required_data : bool
142
+ required
141
143
Set to True when 'data' is required, or False when dealing with
142
144
optional virtual files. [Default is True].
143
145
144
146
Returns
145
147
-------
146
- kind : str
147
- One of ``'arg'``, ``'file'``, ``'grid'``, ``image``, ``'geojson'``,
148
- ``'matrix'``, or ``'vectors'``.
148
+ kind
149
+ The data kind.
149
150
150
151
Examples
151
152
--------
@@ -179,7 +180,7 @@ def data_kind(data=None, required_data=True):
179
180
):
180
181
# One or more files
181
182
kind = "file"
182
- elif isinstance (data , bool | int | float ) or (data is None and not required_data ):
183
+ elif isinstance (data , bool | int | float ) or (data is None and not required ):
183
184
kind = "arg"
184
185
elif isinstance (data , xr .DataArray ):
185
186
kind = "image" if len (data .dims ) == 3 else "grid"
0 commit comments