From 008a56f973625bc3b57c6a8613df16af7bb485fb Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Wed, 17 Jul 2024 17:57:35 +0800 Subject: [PATCH] Remove the unused x/y/z/required_z parameters from data_kind --- pygmt/clib/session.py | 4 +--- pygmt/helpers/utils.py | 22 ++++++++-------------- pygmt/src/plot.py | 2 +- pygmt/src/plot3d.py | 2 +- pygmt/src/text.py | 4 ++-- 5 files changed, 13 insertions(+), 21 deletions(-) diff --git a/pygmt/clib/session.py b/pygmt/clib/session.py index 7a8981fc920..2af356f2e7b 100644 --- a/pygmt/clib/session.py +++ b/pygmt/clib/session.py @@ -1592,9 +1592,7 @@ def virtualfile_in( # noqa: PLR0912 ... print(fout.read().strip()) : N = 3 <7/9> <4/6> <1/3> """ - kind = data_kind( - data, x, y, z, required_z=required_z, required_data=required_data - ) + kind = data_kind(data, required_data=required_data) validate_data_input( data=data, x=x, diff --git a/pygmt/helpers/utils.py b/pygmt/helpers/utils.py index 3648d56857c..99cbfab1731 100644 --- a/pygmt/helpers/utils.py +++ b/pygmt/helpers/utils.py @@ -115,7 +115,7 @@ def validate_data_input( raise GMTInvalidInput("data must provide x, y, and z columns.") -def data_kind(data=None, x=None, y=None, z=None, required_z=False, required_data=True): +def data_kind(data=None, required_data=True): """ Check what kind of data is provided to a module. @@ -137,12 +137,6 @@ def data_kind(data=None, x=None, y=None, z=None, required_z=False, required_data 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. - x/y : 1-D arrays or None - x and y columns as numpy arrays. - z : 1-D array or None - z column as numpy array. To be used optionally when x and y are given. - required_z : bool - State whether the 'z' column is required. required_data : bool Set to True when 'data' is required, or False when dealing with optional virtual files. [Default is True]. @@ -159,19 +153,19 @@ def data_kind(data=None, x=None, y=None, z=None, required_z=False, required_data >>> import numpy as np >>> import xarray as xr >>> import pathlib - >>> data_kind(data=None, x=np.array([1, 2, 3]), y=np.array([4, 5, 6])) + >>> data_kind(data=None) 'vectors' - >>> data_kind(data=np.arange(10).reshape((5, 2)), x=None, y=None) + >>> data_kind(data=np.arange(10).reshape((5, 2))) 'matrix' - >>> data_kind(data="my-data-file.txt", x=None, y=None) + >>> data_kind(data="my-data-file.txt") 'file' - >>> data_kind(data=pathlib.Path("my-data-file.txt"), x=None, y=None) + >>> data_kind(data=pathlib.Path("my-data-file.txt")) 'file' - >>> data_kind(data=None, x=None, y=None, required_data=False) + >>> data_kind(data=None, required_data=False) 'arg' - >>> data_kind(data=2.0, x=None, y=None, required_data=False) + >>> data_kind(data=2.0, required_data=False) 'arg' - >>> data_kind(data=True, x=None, y=None, required_data=False) + >>> data_kind(data=True, required_data=False) 'arg' >>> data_kind(data=xr.DataArray(np.random.rand(4, 3))) 'grid' diff --git a/pygmt/src/plot.py b/pygmt/src/plot.py index 43b26232871..e66f08438e5 100644 --- a/pygmt/src/plot.py +++ b/pygmt/src/plot.py @@ -208,7 +208,7 @@ def plot( # noqa: PLR0912 """ kwargs = self._preprocess(**kwargs) - kind = data_kind(data, x, y) + kind = data_kind(data) extra_arrays = [] if kind == "vectors": # Add more columns for vectors input # Parameters for vector styles diff --git a/pygmt/src/plot3d.py b/pygmt/src/plot3d.py index 65d87761d5c..c86e5e259f1 100644 --- a/pygmt/src/plot3d.py +++ b/pygmt/src/plot3d.py @@ -183,7 +183,7 @@ def plot3d( # noqa: PLR0912 """ kwargs = self._preprocess(**kwargs) - kind = data_kind(data, x, y, z) + kind = data_kind(data) extra_arrays = [] if kind == "vectors": # Add more columns for vectors input diff --git a/pygmt/src/text.py b/pygmt/src/text.py index 04abf12ea3b..484f885997a 100644 --- a/pygmt/src/text.py +++ b/pygmt/src/text.py @@ -180,11 +180,11 @@ def text_( # noqa: PLR0912 # Ensure inputs are either textfiles, x/y/text, or position/text if position is None: - if (x is not None or y is not None) and textfiles is not None: + if any(v is not None for v in (x, y, text)) and textfiles is not None: raise GMTInvalidInput( "Provide either position only, or x/y pairs, or textfiles." ) - kind = data_kind(textfiles, x, y, text) + kind = data_kind(textfiles) if kind == "vectors" and text is None: raise GMTInvalidInput("Must provide text with x/y pairs") else: