Skip to content

Commit f9bf19c

Browse files
committed
Refactor a few tests
1 parent 9fd655b commit f9bf19c

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

pygmt/tests/test_clib_to_numpy.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,25 @@ def _check_result(result, supported):
2525
# Test the _to_numpy function with Python built-in types.
2626
########################################################################################
2727
@pytest.mark.parametrize(
28-
("data", "supported"),
28+
("data", "expected_dtype"),
2929
[
30-
pytest.param([1, 2, 3], True, id="int"),
31-
pytest.param([1.0, 2.0, 3.0], True, id="float"),
30+
pytest.param([1, 2, 3], np.int64, id="int"),
31+
pytest.param([1.0, 2.0, 3.0], np.float64, id="float"),
3232
],
3333
)
34-
def test_to_numpy_python_types_numeric(data, supported):
34+
def test_to_numpy_python_types_numeric(data, expected_dtype):
3535
"""
3636
Test the _to_numpy function with Python built-in numeric types.
3737
"""
3838
result = _to_numpy(data)
39-
_check_result(result, supported)
40-
npt.assert_array_equal(result, data)
39+
_check_result(result, supported=True)
40+
npt.assert_array_equal(result, np.array(data, dtype=expected_dtype), strict=True)
4141

4242

4343
########################################################################################
4444
# Test the _to_numpy function with NumPy arrays.
4545
#
4646
# There are 24 fundamental dtypes in NumPy. Not all of them are supported by PyGMT.
47-
# Reference: https://numpy.org/doc/2.1/reference/arrays.scalars.html
4847
#
4948
# - Numeric dtypes:
5049
# - int8, int16, int32, int64, longlong
@@ -57,6 +56,8 @@ def test_to_numpy_python_types_numeric(data, supported):
5756
# - bytes_
5857
# - object_
5958
# - void
59+
#
60+
# Reference: https://numpy.org/doc/2.1/reference/arrays.scalars.html
6061
########################################################################################
6162
@pytest.mark.parametrize(
6263
("dtype", "supported"),
@@ -84,22 +85,19 @@ def test_to_numpy_ndarray_numpy_dtypes_numeric(dtype, supported):
8485
"""
8586
Test the _to_numpy function with NumPy arrays of NumPy numeric dtypes.
8687
87-
"dtype" is the NumPy dtype to be tested and "supported" is a boolean value
88-
indicating whether the dtype is supported by PyGMT (or the GMT C API).
88+
Test both 1-D and 2-D arrays.
8989
"""
9090
# 1-D array
9191
array = np.array([1, 2, 3], dtype=dtype)
92-
assert array.dtype == dtype
9392
result = _to_numpy(array)
9493
_check_result(result, supported)
95-
npt.assert_array_equal(result, array)
94+
npt.assert_array_equal(result, array, strict=True)
9695

9796
# 2-D array
9897
array = np.array([[1, 2, 3], [4, 5, 6]], dtype=dtype)
99-
assert array.dtype == dtype
10098
result = _to_numpy(array)
10199
_check_result(result, supported)
102-
npt.assert_array_equal(result, array)
100+
npt.assert_array_equal(result, array, strict=True)
103101

104102

105103
########################################################################################
@@ -124,9 +122,7 @@ def test_to_numpy_ndarray_numpy_dtypes_numeric(dtype, supported):
124122
# - CategoricalDtype
125123
# - SparseDtype
126124
# - BooleanDtype
127-
# - ArrowDtype
128-
#
129-
# ArrowDtype is a special dtype that is used to store data in the PyArrow format.
125+
# - ArrowDtype: a special dtype used to store data in the PyArrow format.
130126
#
131127
# References:
132128
# 1. https://pandas.pydata.org/docs/reference/arrays.html

0 commit comments

Comments
 (0)