Skip to content

Commit a0e4226

Browse files
authored
Replace the list of support numpy dtypes with DTYPES_NUMERIC in tests (#3565)
1 parent 82b0c73 commit a0e4226

6 files changed

+14
-23
lines changed

pygmt/tests/test_clib_put_matrix.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import pytest
88
import xarray as xr
99
from pygmt import clib
10+
from pygmt.clib.session import DTYPES_NUMERIC
1011
from pygmt.exceptions import GMTCLibError
1112
from pygmt.helpers import GMTTempFile
1213
from pygmt.tests.test_clib import mock
@@ -17,7 +18,7 @@ def fixture_dtypes():
1718
"""
1819
List of supported numpy dtypes.
1920
"""
20-
return "int8 int16 int32 int64 uint8 uint16 uint32 uint64 float32 float64".split()
21+
return [dtype for dtype in DTYPES_NUMERIC if dtype != np.timedelta64]
2122

2223

2324
@pytest.mark.benchmark

pygmt/tests/test_clib_put_vector.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import numpy.testing as npt
1010
import pytest
1111
from pygmt import clib
12+
from pygmt.clib.session import DTYPES_NUMERIC
1213
from pygmt.exceptions import GMTCLibError, GMTInvalidInput
1314
from pygmt.helpers import GMTTempFile
1415

@@ -18,7 +19,7 @@ def fixture_dtypes():
1819
"""
1920
List of supported numpy dtypes.
2021
"""
21-
return "int8 int16 int32 int64 uint8 uint16 uint32 uint64 float32 float64".split()
22+
return [dtype for dtype in DTYPES_NUMERIC if dtype != np.timedelta64]
2223

2324

2425
@pytest.mark.benchmark

pygmt/tests/test_clib_virtualfile_from_matrix.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import numpy as np
66
import pytest
77
from pygmt import clib
8+
from pygmt.clib.session import DTYPES_NUMERIC
89
from pygmt.helpers import GMTTempFile
910

1011

@@ -13,7 +14,7 @@ def fixture_dtypes():
1314
"""
1415
List of supported numpy dtypes.
1516
"""
16-
return "int8 int16 int32 int64 uint8 uint16 uint32 uint64 float32 float64".split()
17+
return [dtype for dtype in DTYPES_NUMERIC if dtype != np.timedelta64]
1718

1819

1920
@pytest.mark.benchmark

pygmt/tests/test_clib_virtualfile_from_vectors.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import pandas as pd
99
import pytest
1010
from pygmt import clib
11+
from pygmt.clib.session import DTYPES_NUMERIC
1112
from pygmt.exceptions import GMTInvalidInput
1213
from pygmt.helpers import GMTTempFile
1314

@@ -17,7 +18,7 @@ def fixture_dtypes():
1718
"""
1819
List of supported numpy dtypes.
1920
"""
20-
return "int8 int16 int32 int64 uint8 uint16 uint32 uint64 float32 float64".split()
21+
return [dtype for dtype in DTYPES_NUMERIC if dtype != np.timedelta64]
2122

2223

2324
@pytest.fixture(scope="module", name="dtypes_pandas")
@@ -26,10 +27,8 @@ def fixture_dtypes_pandas(dtypes):
2627
List of supported pandas dtypes.
2728
"""
2829
dtypes_pandas = dtypes.copy()
29-
3030
if find_spec("pyarrow") is not None:
31-
dtypes_pandas.extend([f"{dtype}[pyarrow]" for dtype in dtypes_pandas])
32-
31+
dtypes_pandas.extend([f"{np.dtype(dtype).name}[pyarrow]" for dtype in dtypes])
3332
return tuple(dtypes_pandas)
3433

3534

pygmt/tests/test_clib_virtualfiles.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
Test the Session.open_virtualfile method.
33
"""
44

5-
from importlib.util import find_spec
65
from pathlib import Path
76

87
import numpy as np
98
import pytest
109
from pygmt import clib
10+
from pygmt.clib.session import DTYPES_NUMERIC
1111
from pygmt.exceptions import GMTCLibError, GMTInvalidInput
1212
from pygmt.helpers import GMTTempFile
1313
from pygmt.tests.test_clib import mock
@@ -28,20 +28,7 @@ def fixture_dtypes():
2828
"""
2929
List of supported numpy dtypes.
3030
"""
31-
return "int8 int16 int32 int64 uint8 uint16 uint32 uint64 float32 float64".split()
32-
33-
34-
@pytest.fixture(scope="module", name="dtypes_pandas")
35-
def fixture_dtypes_pandas(dtypes):
36-
"""
37-
List of supported pandas dtypes.
38-
"""
39-
dtypes_pandas = dtypes.copy()
40-
41-
if find_spec("pyarrow") is not None:
42-
dtypes_pandas.extend([f"{dtype}[pyarrow]" for dtype in dtypes_pandas])
43-
44-
return tuple(dtypes_pandas)
31+
return [dtype for dtype in DTYPES_NUMERIC if dtype != np.timedelta64]
4532

4633

4734
@pytest.mark.benchmark

pygmt/tests/test_grdimage_image.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
Test Figure.grdimage on 3-band RGB images.
33
"""
44

5+
import numpy as np
56
import pytest
67
from pygmt import Figure
8+
from pygmt.clib.session import DTYPES_NUMERIC
79
from pygmt.datasets import load_blue_marble
810

911
rioxarray = pytest.importorskip("rioxarray")
@@ -43,7 +45,7 @@ def test_grdimage_image_dataarray(xr_image):
4345

4446
@pytest.mark.parametrize(
4547
"dtype",
46-
["int8", "uint16", "int16", "uint32", "int32", "float32", "float64"],
48+
[dtype for dtype in DTYPES_NUMERIC if dtype not in {np.uint8, np.timedelta64}],
4749
)
4850
def test_grdimage_image_dataarray_unsupported_dtype(dtype, xr_image):
4951
"""

0 commit comments

Comments
 (0)