From a1e67d3432c0818fcc1cf2e3eb299a7a83e515b2 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 11 Oct 2024 08:26:46 +0800 Subject: [PATCH] Rename 'none' kind to 'empty' --- pygmt/clib/session.py | 8 ++++---- pygmt/helpers/utils.py | 18 +++++++++--------- pygmt/src/legend.py | 2 +- pygmt/src/plot.py | 2 +- pygmt/src/plot3d.py | 2 +- pygmt/src/text.py | 4 ++-- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/pygmt/clib/session.py b/pygmt/clib/session.py index b369d0f2a47..fde15176c69 100644 --- a/pygmt/clib/session.py +++ b/pygmt/clib/session.py @@ -1775,7 +1775,7 @@ def virtualfile_in( # noqa: PLR0912 if check_kind == "raster": valid_kinds += ("grid", "image") elif check_kind == "vector": - valid_kinds += ("none", "matrix", "vectors", "geojson") + valid_kinds += ("empty", "matrix", "vectors", "geojson") if kind not in valid_kinds: raise GMTInvalidInput( f"Unrecognized data type for {check_kind}: {type(data)}" @@ -1783,14 +1783,14 @@ def virtualfile_in( # noqa: PLR0912 # Decide which virtualfile_from_ function to use _virtualfile_from = { - "file": contextlib.nullcontext, "arg": contextlib.nullcontext, + "empty": self.virtualfile_from_vectors, + "file": contextlib.nullcontext, "geojson": tempfile_from_geojson, "grid": self.virtualfile_from_grid, "image": tempfile_from_image, "stringio": self.virtualfile_from_stringio, "matrix": self.virtualfile_from_matrix, - "none": self.virtualfile_from_vectors, "vectors": self.virtualfile_from_vectors, }[kind] @@ -1806,7 +1806,7 @@ def virtualfile_in( # noqa: PLR0912 ) warnings.warn(message=msg, category=RuntimeWarning, stacklevel=2) _data = (data,) if not isinstance(data, pathlib.PurePath) else (str(data),) - elif kind == "none": + elif kind == "empty": # data is None, so data must be given via x/y/z. _data = [x, y] if z is not None: diff --git a/pygmt/helpers/utils.py b/pygmt/helpers/utils.py index 586710f8ac4..74e2655dc67 100644 --- a/pygmt/helpers/utils.py +++ b/pygmt/helpers/utils.py @@ -191,7 +191,7 @@ def _check_encoding( def data_kind( data: Any, required: bool = True ) -> Literal[ - "arg", "file", "geojson", "grid", "image", "matrix", "none", "stringio", "vectors" + "arg", "empty", "file", "geojson", "grid", "image", "matrix", "stringio", "vectors" ]: r""" Check the kind of data that is provided to a module. @@ -199,10 +199,10 @@ def data_kind( The argument passed to the ``data`` parameter can have any data type. The following data kinds are recognized and returned as ``kind``: - - ``"none"`: ``data`` is ``None`` and ``required=True``. It means the data is given - via a series of vectors like x/y/z - ``"arg"``: ``data`` is ``None`` and ``required=False``, or bool, int, float, representing an optional argument, used for dealing with optional virtual files + - ``"empty"`: ``data`` is ``None`` and ``required=True``. It means the data is given + via a series of vectors like x/y/z - ``"file"``: a string or a :class:`pathlib.PurePath` object or a sequence of them, representing one or more file names - ``"geojson"``: a geo-like Python object that implements ``__geo_interface__`` @@ -244,6 +244,11 @@ def data_kind( >>> data_kind(data=None, required=False) 'arg' + The "empty" kind: + + >>> data_kind(data=None) + 'empty' + The "file" kind: >>> [data_kind(data=data) for data in ("file.txt", ("file1.txt", "file2.txt"))] @@ -295,15 +300,10 @@ def data_kind( 'vectors' >>> data_kind(data=pd.Series([1, 2, 3], name="x")) # pd.Series 'vectors' - - The "none" kind: - - >>> data_kind(data=None) - 'none' """ match data: case None if required: # No data provided and required=True. - kind = "none" + kind = "empty" case str() | pathlib.PurePath(): # One file. kind = "file" case list() | tuple() if all( diff --git a/pygmt/src/legend.py b/pygmt/src/legend.py index 197dad9b347..f6e2d61f34f 100644 --- a/pygmt/src/legend.py +++ b/pygmt/src/legend.py @@ -91,7 +91,7 @@ def legend( kwargs["F"] = box kind = data_kind(spec) - if kind not in {"none", "file", "stringio"}: + if kind not in {"empty", "file", "stringio"}: raise GMTInvalidInput(f"Unrecognized data type: {type(spec)}") if kind == "file" and is_nonstr_iter(spec): raise GMTInvalidInput("Only one legend specification file is allowed.") diff --git a/pygmt/src/plot.py b/pygmt/src/plot.py index 655870f8904..4565d02e0db 100644 --- a/pygmt/src/plot.py +++ b/pygmt/src/plot.py @@ -206,7 +206,7 @@ def plot(self, data=None, x=None, y=None, size=None, direction=None, **kwargs): kind = data_kind(data) extra_arrays = [] - if kind == "none": # Add more columns for vectors input + if kind == "empty": # Add more columns for vectors input # Parameters for vector styles if ( kwargs.get("S") is not None diff --git a/pygmt/src/plot3d.py b/pygmt/src/plot3d.py index 2dde128e412..31695a82464 100644 --- a/pygmt/src/plot3d.py +++ b/pygmt/src/plot3d.py @@ -184,7 +184,7 @@ def plot3d( kind = data_kind(data) extra_arrays = [] - if kind == "none": # Add more columns for vectors input + if kind == "empty": # Add more columns for vectors input # Parameters for vector styles if ( kwargs.get("S") is not None diff --git a/pygmt/src/text.py b/pygmt/src/text.py index b59eebcd34a..9f0f80ccde1 100644 --- a/pygmt/src/text.py +++ b/pygmt/src/text.py @@ -193,7 +193,7 @@ def text_( # noqa: PLR0912 raise GMTInvalidInput("'text' can't be None or array when 'position' is given.") if textfiles is not None and text is not None: raise GMTInvalidInput("'text' can't be specified when 'textfiles' is given.") - if kind == "none" and text is None: + if kind == "empty" and text is None: raise GMTInvalidInput("Must provide text with x/y pairs.") # Arguments that can accept arrays. @@ -217,7 +217,7 @@ def text_( # noqa: PLR0912 extra_arrays = [] confdict = {} - if kind == "none": + if kind == "empty": for arg, flag, name in array_args: if is_nonstr_iter(arg): kwargs["F"] += flag