Skip to content

Commit

Permalink
data_kind: Change the parameter name from required_data to required
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman committed Jul 17, 2024
1 parent 008a56f commit 46fb307
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pygmt/clib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,7 @@ def virtualfile_in( # noqa: PLR0912
... print(fout.read().strip())
<vector memory>: N = 3 <7/9> <4/6> <1/3>
"""
kind = data_kind(data, required_data=required_data)
kind = data_kind(data, required=required_data)
validate_data_input(
data=data,
x=x,
Expand Down
21 changes: 11 additions & 10 deletions pygmt/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import warnings
import webbrowser
from collections.abc import Iterable, Sequence
from typing import Any
from typing import Any, Literal

import xarray as xr
from pygmt.encodings import charset
Expand Down Expand Up @@ -115,7 +115,9 @@ def validate_data_input(
raise GMTInvalidInput("data must provide x, y, and z columns.")


def data_kind(data=None, required_data=True):
def data_kind(
data: Any = None, required: bool = True
) -> Literal["arg", "file", "geojson", "grid", "image", "matrix", "vectors"]:
"""
Check what kind of data is provided to a module.
Expand All @@ -137,15 +139,14 @@ def data_kind(data=None, required_data=True):
Pass in either a file name or :class:`pathlib.Path` to an ASCII data
table, an :class:`xarray.DataArray`, a 1-D/2-D
{table-classes} or an option argument.
required_data : bool
required
Set to True when 'data' is required, or False when dealing with
optional virtual files. [Default is True].
Returns
-------
kind : str
One of ``'arg'``, ``'file'``, ``'grid'``, ``image``, ``'geojson'``,
``'matrix'``, or ``'vectors'``.
kind
The data kind.
Examples
--------
Expand All @@ -161,11 +162,11 @@ def data_kind(data=None, required_data=True):
'file'
>>> data_kind(data=pathlib.Path("my-data-file.txt"))
'file'
>>> data_kind(data=None, required_data=False)
>>> data_kind(data=None, required=False)
'arg'
>>> data_kind(data=2.0, required_data=False)
>>> data_kind(data=2.0, required=False)
'arg'
>>> data_kind(data=True, required_data=False)
>>> data_kind(data=True, required=False)
'arg'
>>> data_kind(data=xr.DataArray(np.random.rand(4, 3)))
'grid'
Expand All @@ -179,7 +180,7 @@ def data_kind(data=None, required_data=True):
):
# One or more files
kind = "file"
elif isinstance(data, bool | int | float) or (data is None and not required_data):
elif isinstance(data, bool | int | float) or (data is None and not required):
kind = "arg"
elif isinstance(data, xr.DataArray):
kind = "image" if len(data.dims) == 3 else "grid"
Expand Down

0 comments on commit 46fb307

Please sign in to comment.