@@ -25,26 +25,25 @@ def _check_result(result, supported):
25
25
# Test the _to_numpy function with Python built-in types.
26
26
########################################################################################
27
27
@pytest .mark .parametrize (
28
- ("data" , "supported " ),
28
+ ("data" , "expected_dtype " ),
29
29
[
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" ),
32
32
],
33
33
)
34
- def test_to_numpy_python_types_numeric (data , supported ):
34
+ def test_to_numpy_python_types_numeric (data , expected_dtype ):
35
35
"""
36
36
Test the _to_numpy function with Python built-in numeric types.
37
37
"""
38
38
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 )
41
41
42
42
43
43
########################################################################################
44
44
# Test the _to_numpy function with NumPy arrays.
45
45
#
46
46
# 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
48
47
#
49
48
# - Numeric dtypes:
50
49
# - int8, int16, int32, int64, longlong
@@ -57,6 +56,8 @@ def test_to_numpy_python_types_numeric(data, supported):
57
56
# - bytes_
58
57
# - object_
59
58
# - void
59
+ #
60
+ # Reference: https://numpy.org/doc/2.1/reference/arrays.scalars.html
60
61
########################################################################################
61
62
@pytest .mark .parametrize (
62
63
("dtype" , "supported" ),
@@ -84,22 +85,19 @@ def test_to_numpy_ndarray_numpy_dtypes_numeric(dtype, supported):
84
85
"""
85
86
Test the _to_numpy function with NumPy arrays of NumPy numeric dtypes.
86
87
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.
89
89
"""
90
90
# 1-D array
91
91
array = np .array ([1 , 2 , 3 ], dtype = dtype )
92
- assert array .dtype == dtype
93
92
result = _to_numpy (array )
94
93
_check_result (result , supported )
95
- npt .assert_array_equal (result , array )
94
+ npt .assert_array_equal (result , array , strict = True )
96
95
97
96
# 2-D array
98
97
array = np .array ([[1 , 2 , 3 ], [4 , 5 , 6 ]], dtype = dtype )
99
- assert array .dtype == dtype
100
98
result = _to_numpy (array )
101
99
_check_result (result , supported )
102
- npt .assert_array_equal (result , array )
100
+ npt .assert_array_equal (result , array , strict = True )
103
101
104
102
105
103
########################################################################################
@@ -124,9 +122,7 @@ def test_to_numpy_ndarray_numpy_dtypes_numeric(dtype, supported):
124
122
# - CategoricalDtype
125
123
# - SparseDtype
126
124
# - 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.
130
126
#
131
127
# References:
132
128
# 1. https://pandas.pydata.org/docs/reference/arrays.html
0 commit comments