Skip to content

Commit f151a46

Browse files
hmaarrfkandersy005
authored andcommitted
Fix syntax error in test related to cupy (#9000)
I suspect the CIs don't have cupy which meant that this line didn't get hit. Recreation: ``` mamba create --name xr_py10 python=3.10 --channel conda-forge --override-channels mamba activate xr_py10 pip install -e . -vv pip install pytest mamba install cupy ``` ``` pytest xarray/tests/test_array_api.py -x ``` Fails on my machine. Happy to provide more info
1 parent 2fd3b8b commit f151a46

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

xarray/core/duck_array_ops.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,10 @@ def as_shared_dtype(scalars_or_arrays, xp=np):
233233
raise ValueError(
234234
f"Cannot cast arrays to shared type, found array types {[x.dtype for x in scalars_or_arrays]}"
235235
)
236-
elif array_type_cupy := array_type("cupy") and any( # noqa: F841
237-
isinstance(x, array_type_cupy) for x in scalars_or_arrays # noqa: F821
238-
):
236+
237+
# Avoid calling array_type("cupy") repeatidely in the any check
238+
array_type_cupy = array_type("cupy")
239+
if any(isinstance(x, array_type_cupy) for x in scalars_or_arrays):
239240
import cupy as cp
240241

241242
arrays = [asarray(x, xp=cp) for x in scalars_or_arrays]

0 commit comments

Comments
 (0)