|
3 | 3 | is_dask_array, is_jax_array, is_pydata_sparse_array,
|
4 | 4 | is_numpy_namespace, is_cupy_namespace, is_torch_namespace,
|
5 | 5 | is_dask_namespace, is_jax_namespace, is_pydata_sparse_namespace,
|
| 6 | + is_array_api_strict_namespace, |
6 | 7 | )
|
7 | 8 |
|
8 | 9 | from array_api_compat import (
|
|
31 | 32 | 'dask.array': 'is_dask_namespace',
|
32 | 33 | 'jax.numpy': 'is_jax_namespace',
|
33 | 34 | 'sparse': 'is_pydata_sparse_namespace',
|
| 35 | + 'array_api_strict': 'is_array_api_strict_namespace', |
34 | 36 | }
|
35 | 37 |
|
36 | 38 |
|
@@ -72,7 +74,12 @@ def test_xp_is_array_generics(library):
|
72 | 74 | is_func = globals()[func]
|
73 | 75 | if is_func(x0):
|
74 | 76 | matches.append(library2)
|
75 |
| - assert matches in ([library], ["numpy"]) |
| 77 | + |
| 78 | + if library == "array_api_strict": |
| 79 | + # There is no is_array_api_strict_array() function |
| 80 | + assert matches == [] |
| 81 | + else: |
| 82 | + assert matches in ([library], ["numpy"]) |
76 | 83 |
|
77 | 84 |
|
78 | 85 | @pytest.mark.parametrize("library", all_libraries)
|
@@ -151,26 +158,33 @@ def test_to_device_host(library):
|
151 | 158 | @pytest.mark.parametrize("target_library", is_array_functions.keys())
|
152 | 159 | @pytest.mark.parametrize("source_library", is_array_functions.keys())
|
153 | 160 | def test_asarray_cross_library(source_library, target_library, request):
|
154 |
| - if source_library == "dask.array" and target_library == "torch": |
| 161 | + def _xfail(reason: str) -> None: |
155 | 162 | # Allow rest of test to execute instead of immediately xfailing
|
156 | 163 | # xref https://github.com/pandas-dev/pandas/issues/38902
|
| 164 | + request.node.add_marker(pytest.mark.xfail(reason=reason)) |
157 | 165 |
|
| 166 | + if source_library == "dask.array" and target_library == "torch": |
158 | 167 | # TODO: remove xfail once
|
159 | 168 | # https://github.com/dask/dask/issues/8260 is resolved
|
160 |
| - request.node.add_marker(pytest.mark.xfail(reason="Bug in dask raising error on conversion")) |
161 |
| - if source_library == "cupy" and target_library != "cupy": |
| 169 | + _xfail(reason="Bug in dask raising error on conversion") |
| 170 | + elif source_library == "jax.numpy" and target_library == "torch": |
| 171 | + _xfail(reason="casts int to float") |
| 172 | + elif source_library == "cupy" and target_library != "cupy": |
162 | 173 | # cupy explicitly disallows implicit conversions to CPU
|
163 | 174 | pytest.skip(reason="cupy does not support implicit conversion to CPU")
|
164 | 175 | elif source_library == "sparse" and target_library != "sparse":
|
165 | 176 | pytest.skip(reason="`sparse` does not allow implicit densification")
|
| 177 | + |
166 | 178 | src_lib = import_(source_library, wrapper=True)
|
167 | 179 | tgt_lib = import_(target_library, wrapper=True)
|
168 | 180 | is_tgt_type = globals()[is_array_functions[target_library]]
|
169 | 181 |
|
170 |
| - a = src_lib.asarray([1, 2, 3]) |
| 182 | + a = src_lib.asarray([1, 2, 3], dtype=src_lib.int32) |
171 | 183 | b = tgt_lib.asarray(a)
|
172 | 184 |
|
173 | 185 | assert is_tgt_type(b), f"Expected {b} to be a {tgt_lib.ndarray}, but was {type(b)}"
|
| 186 | + assert b.dtype == tgt_lib.int32 |
| 187 | + |
174 | 188 |
|
175 | 189 | @pytest.mark.parametrize("library", wrapped_libraries)
|
176 | 190 | def test_asarray_copy(library):
|
|
0 commit comments