From 41d8ad5272cc07893b9958a06253ccec6c08d215 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 31 Oct 2024 10:52:52 +0800 Subject: [PATCH 1/4] 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..cf1a71f99ec 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.session 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..7e1dd0d9310 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.session 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..6d4c855ac05 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.session 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..e737e87d63d 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.session 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..d6f3965065e 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.session 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..5314c3882a2 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 not in {np.uint8, np.timedelta64}], ) def test_grdimage_image_dataarray_unsupported_dtype(dtype, xr_image): """ From 962e58dd0074d5fe57ac0fc7f2f55a73abd1b7e7 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 31 Oct 2024 11:15:00 +0800 Subject: [PATCH 2/4] Fix the dtypes_pandas --- pygmt/tests/test_clib_virtualfile_from_vectors.py | 4 +--- pygmt/tests/test_clib_virtualfiles.py | 14 -------------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/pygmt/tests/test_clib_virtualfile_from_vectors.py b/pygmt/tests/test_clib_virtualfile_from_vectors.py index e737e87d63d..041bc7a803c 100644 --- a/pygmt/tests/test_clib_virtualfile_from_vectors.py +++ b/pygmt/tests/test_clib_virtualfile_from_vectors.py @@ -27,10 +27,8 @@ def fixture_dtypes_pandas(dtypes): List of supported pandas dtypes. """ dtypes_pandas = dtypes.copy() - if find_spec("pyarrow") is not None: - dtypes_pandas.extend([f"{dtype}[pyarrow]" for dtype in dtypes_pandas]) - + dtypes_pandas.extend([f"{np.dtype(dtype).name}[pyarrow]" for dtype in dtypes]) return tuple(dtypes_pandas) diff --git a/pygmt/tests/test_clib_virtualfiles.py b/pygmt/tests/test_clib_virtualfiles.py index d6f3965065e..a45a662de71 100644 --- a/pygmt/tests/test_clib_virtualfiles.py +++ b/pygmt/tests/test_clib_virtualfiles.py @@ -2,7 +2,6 @@ Test the Session.open_virtualfile method. """ -from importlib.util import find_spec from pathlib import Path import numpy as np @@ -32,19 +31,6 @@ def fixture_dtypes(): return [dtype for dtype in DTYPES_NUMERIC if dtype != np.timedelta64] -@pytest.fixture(scope="module", name="dtypes_pandas") -def fixture_dtypes_pandas(dtypes): - """ - List of supported pandas dtypes. - """ - dtypes_pandas = dtypes.copy() - - if find_spec("pyarrow") is not None: - dtypes_pandas.extend([f"{dtype}[pyarrow]" for dtype in dtypes_pandas]) - - return tuple(dtypes_pandas) - - @pytest.mark.benchmark def test_open_virtualfile(dtypes): """ From 8cdc654e1acc0b6f5e026df960c10917835eb416 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 31 Oct 2024 12:40:46 +0800 Subject: [PATCH 3/4] Support 1-D/2-D numpy arrays with longlong and ulonglong dtype --- pygmt/clib/session.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pygmt/clib/session.py b/pygmt/clib/session.py index bdd8a13a1d3..16e4e7e1d00 100644 --- a/pygmt/clib/session.py +++ b/pygmt/clib/session.py @@ -88,10 +88,12 @@ np.int16: "GMT_SHORT", np.int32: "GMT_INT", np.int64: "GMT_LONG", + np.longlong: "GMT_LONG", np.uint8: "GMT_UCHAR", np.uint16: "GMT_USHORT", np.uint32: "GMT_UINT", np.uint64: "GMT_ULONG", + np.ulonglong: "GMT_ULONG", np.float32: "GMT_FLOAT", np.float64: "GMT_DOUBLE", np.timedelta64: "GMT_LONG", @@ -948,8 +950,9 @@ def put_vector(self, dataset: ctp.c_void_p, column: int, vector: np.ndarray): The dataset must be created by :meth:`pygmt.clib.Session.create_data` first with ``family="GMT_IS_DATASET|GMT_VIA_VECTOR"``. - Not all numpy dtypes are supported, only: int8, int16, int32, int64, uint8, - uint16, uint32, uint64, float32, float64, str\_, and datetime64. + Not all numpy dtypes are supported, only: int8, int16, int32, int64, longlong, + uint8, uint16, uint32, uint64, ulonglong, float32, float64, str\_, and + datetime64. .. warning:: The numpy array must be C contiguous in memory. Use @@ -1060,8 +1063,8 @@ def put_matrix(self, dataset: ctp.c_void_p, matrix: np.ndarray, pad: int = 0): The dataset must be created by :meth:`pygmt.clib.Session.create_data` first with ``family="GMT_IS_DATASET|GMT_VIA_MATRIX"``. - Not all numpy dtypes are supported, only: int8, int16, int32, int64, uint8, - uint16, uint32, uint64, float32, and float64. + Not all numpy dtypes are supported, only: int8, int16, int32, int64, longlong, + uint8, uint16, uint32, uint64, ulonglong, float32, and float64. .. warning:: The numpy array must be C contiguous in memory. Use From 01c936b7c7a73fbae018338100f5149e50bb41ed Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 4 Nov 2024 08:10:13 +0800 Subject: [PATCH 4/4] Mention timedelta64 --- pygmt/clib/session.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/clib/session.py b/pygmt/clib/session.py index 16e4e7e1d00..c98c65e628f 100644 --- a/pygmt/clib/session.py +++ b/pygmt/clib/session.py @@ -951,8 +951,8 @@ def put_vector(self, dataset: ctp.c_void_p, column: int, vector: np.ndarray): ``family="GMT_IS_DATASET|GMT_VIA_VECTOR"``. Not all numpy dtypes are supported, only: int8, int16, int32, int64, longlong, - uint8, uint16, uint32, uint64, ulonglong, float32, float64, str\_, and - datetime64. + uint8, uint16, uint32, uint64, ulonglong, float32, float64, str\_, datetime64, + and timedelta64. .. warning:: The numpy array must be C contiguous in memory. Use