From d31c2ff29570b338548c43c189bac81979837752 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 31 Oct 2024 10:52:52 +0800 Subject: [PATCH] Simplify the list of support numpy dtypes with DTYPES_NUMERIC --- pygmt/tests/test_clib_put_matrix.py | 3 ++- pygmt/tests/test_clib_put_vector.py | 3 ++- pygmt/tests/test_clib_virtualfile_from_matrix.py | 3 ++- pygmt/tests/test_clib_virtualfile_from_vectors.py | 3 ++- pygmt/tests/test_clib_virtualfiles.py | 3 ++- pygmt/tests/test_grdimage_image.py | 4 +++- 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/pygmt/tests/test_clib_put_matrix.py b/pygmt/tests/test_clib_put_matrix.py index ff85a7430e8..4e8b5b11a31 100644 --- a/pygmt/tests/test_clib_put_matrix.py +++ b/pygmt/tests/test_clib_put_matrix.py @@ -7,6 +7,7 @@ import pytest import xarray as xr from pygmt import clib +from pygmt.clib.sessions import DTYPES_NUMERIC from pygmt.exceptions import GMTCLibError from pygmt.helpers import GMTTempFile from pygmt.tests.test_clib import mock @@ -17,7 +18,7 @@ def fixture_dtypes(): """ List of supported numpy dtypes. """ - return "int8 int16 int32 int64 uint8 uint16 uint32 uint64 float32 float64".split() + return [dtype for dtype in DTYPES_NUMERIC if dtype != np.timedelta64] @pytest.mark.benchmark diff --git a/pygmt/tests/test_clib_put_vector.py b/pygmt/tests/test_clib_put_vector.py index d42ee9afbba..6eab1c3cf88 100644 --- a/pygmt/tests/test_clib_put_vector.py +++ b/pygmt/tests/test_clib_put_vector.py @@ -9,6 +9,7 @@ import numpy.testing as npt import pytest from pygmt import clib +from pygmt.clib.sessions import DTYPES_NUMERIC from pygmt.exceptions import GMTCLibError, GMTInvalidInput from pygmt.helpers import GMTTempFile @@ -18,7 +19,7 @@ def fixture_dtypes(): """ List of supported numpy dtypes. """ - return "int8 int16 int32 int64 uint8 uint16 uint32 uint64 float32 float64".split() + return [dtype for dtype in DTYPES_NUMERIC if dtype != np.timedelta64] @pytest.mark.benchmark diff --git a/pygmt/tests/test_clib_virtualfile_from_matrix.py b/pygmt/tests/test_clib_virtualfile_from_matrix.py index 6d1a42fa14b..7b4c57fdf84 100644 --- a/pygmt/tests/test_clib_virtualfile_from_matrix.py +++ b/pygmt/tests/test_clib_virtualfile_from_matrix.py @@ -5,6 +5,7 @@ import numpy as np import pytest from pygmt import clib +from pygmt.clib.sessions import DTYPES_NUMERIC from pygmt.helpers import GMTTempFile @@ -13,7 +14,7 @@ def fixture_dtypes(): """ List of supported numpy dtypes. """ - return "int8 int16 int32 int64 uint8 uint16 uint32 uint64 float32 float64".split() + return [dtype for dtype in DTYPES_NUMERIC if dtype != np.timedelta64] @pytest.mark.benchmark diff --git a/pygmt/tests/test_clib_virtualfile_from_vectors.py b/pygmt/tests/test_clib_virtualfile_from_vectors.py index 18cb4053f37..f1acab47a74 100644 --- a/pygmt/tests/test_clib_virtualfile_from_vectors.py +++ b/pygmt/tests/test_clib_virtualfile_from_vectors.py @@ -8,6 +8,7 @@ import pandas as pd import pytest from pygmt import clib +from pygmt.clib.sessions import DTYPES_NUMERIC from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import GMTTempFile @@ -17,7 +18,7 @@ def fixture_dtypes(): """ List of supported numpy dtypes. """ - return "int8 int16 int32 int64 uint8 uint16 uint32 uint64 float32 float64".split() + return [dtype for dtype in DTYPES_NUMERIC if dtype != np.timedelta64] @pytest.fixture(scope="module", name="dtypes_pandas") diff --git a/pygmt/tests/test_clib_virtualfiles.py b/pygmt/tests/test_clib_virtualfiles.py index a05790894d0..ee5995ccaf8 100644 --- a/pygmt/tests/test_clib_virtualfiles.py +++ b/pygmt/tests/test_clib_virtualfiles.py @@ -8,6 +8,7 @@ import numpy as np import pytest from pygmt import clib +from pygmt.clib.sessions import DTYPES_NUMERIC from pygmt.exceptions import GMTCLibError, GMTInvalidInput from pygmt.helpers import GMTTempFile from pygmt.tests.test_clib import mock @@ -28,7 +29,7 @@ def fixture_dtypes(): """ List of supported numpy dtypes. """ - return "int8 int16 int32 int64 uint8 uint16 uint32 uint64 float32 float64".split() + return [dtype for dtype in DTYPES_NUMERIC if dtype != np.timedelta64] @pytest.fixture(scope="module", name="dtypes_pandas") diff --git a/pygmt/tests/test_grdimage_image.py b/pygmt/tests/test_grdimage_image.py index e2ec8980d18..de0e73cb525 100644 --- a/pygmt/tests/test_grdimage_image.py +++ b/pygmt/tests/test_grdimage_image.py @@ -2,8 +2,10 @@ Test Figure.grdimage on 3-band RGB images. """ +import numpy as np import pytest from pygmt import Figure +from pygmt.clib.session import DTYPES_NUMERIC from pygmt.datasets import load_blue_marble rioxarray = pytest.importorskip("rioxarray") @@ -43,7 +45,7 @@ def test_grdimage_image_dataarray(xr_image): @pytest.mark.parametrize( "dtype", - ["int8", "uint16", "int16", "uint32", "int32", "float32", "float64"], + [dtype for dtype in DTYPES_NUMERIC if dtype != np.uint8], ) def test_grdimage_image_dataarray_unsupported_dtype(dtype, xr_image): """