|
1 | 1 | """Unit tests for the type converter module.""" |
2 | 2 |
|
| 3 | +import numpy as np |
3 | 4 | import pytest |
4 | | -from numpy import dtype as np_dtype |
5 | 5 |
|
6 | 6 | from mdio.converters.type_converter import to_numpy_dtype |
7 | 7 | from mdio.converters.type_converter import to_scalar_type |
@@ -58,34 +58,34 @@ def test_to_numpy_dtype(supported_scalar_types_map: tuple[ScalarType, str], a_st |
58 | 58 | # Test 1: ScalarType cases - all supported scalar types |
59 | 59 | for scalar_type, expected_numpy_type in supported_scalar_types_map: |
60 | 60 | result = to_numpy_dtype(scalar_type) |
61 | | - expected = np_dtype(expected_numpy_type) |
| 61 | + expected = np.dtype(expected_numpy_type) |
62 | 62 | assert result == expected |
63 | | - assert isinstance(result, np_dtype) |
| 63 | + assert isinstance(result, np.dtype) |
64 | 64 | assert result.name == expected.name |
65 | 65 |
|
66 | 66 | # Test 2: StructuredType with multiple fields |
67 | 67 | result_multi = to_numpy_dtype(a_structured_type) |
68 | | - expected_multi = np_dtype( |
| 68 | + expected_multi = np.dtype( |
69 | 69 | [("x", "float64"), ("y", "float64"), ("z", "float64"), ("id", "int32"), ("valid", "bool")] |
70 | 70 | ) |
71 | 71 |
|
72 | 72 | assert result_multi == expected_multi |
73 | | - assert isinstance(result_multi, np_dtype) |
| 73 | + assert isinstance(result_multi, np.dtype) |
74 | 74 | assert len(result_multi.names) == 5 |
75 | 75 | assert set(result_multi.names) == {"x", "y", "z", "id", "valid"} |
76 | 76 |
|
77 | 77 |
|
78 | 78 | def test_to_scalar_type(supported_scalar_types_map: tuple[ScalarType, str]) -> None: |
79 | 79 | """Test for to_scalar_type function.""" |
80 | 80 | for expected_mdio_type, numpy_type in supported_scalar_types_map: |
81 | | - result = to_scalar_type(np_dtype(numpy_type)) |
| 81 | + result = to_scalar_type(np.dtype(numpy_type)) |
82 | 82 | assert result == expected_mdio_type |
83 | 83 |
|
84 | 84 |
|
85 | 85 | def test_to_structured_type(a_structured_type: StructuredType) -> None: |
86 | 86 | """Test for to_structured_type function.""" |
87 | | - dtype = np_dtype([("x", "float64"), ("y", "float64"), ("z", "float64"), ("id", "int32"), ("valid", "bool")]) |
| 87 | + dtype = np.dtype([("x", "float64"), ("y", "float64"), ("z", "float64"), ("id", "int32"), ("valid", "bool")]) |
88 | 88 | assert a_structured_type == to_structured_type(dtype) |
89 | 89 |
|
90 | | - dtype = np_dtype([("x", "<f8"), ("y", "<f8"), ("z", "<f8"), ("id", "<i4"), ("valid", "?")]) |
| 90 | + dtype = np.dtype([("x", "<f8"), ("y", "<f8"), ("z", "<f8"), ("id", "<i4"), ("valid", "?")]) |
91 | 91 | assert a_structured_type == to_structured_type(dtype) |
0 commit comments