From f151a46df20b065b8d86e7c9ccc8ae3cefe6316d Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Sun, 5 May 2024 14:05:08 -0400 Subject: [PATCH] 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 --- xarray/core/duck_array_ops.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/xarray/core/duck_array_ops.py b/xarray/core/duck_array_ops.py index d95dfa566cc..23be37618b0 100644 --- a/xarray/core/duck_array_ops.py +++ b/xarray/core/duck_array_ops.py @@ -233,9 +233,10 @@ def as_shared_dtype(scalars_or_arrays, xp=np): raise ValueError( f"Cannot cast arrays to shared type, found array types {[x.dtype for x in scalars_or_arrays]}" ) - elif array_type_cupy := array_type("cupy") and any( # noqa: F841 - isinstance(x, array_type_cupy) for x in scalars_or_arrays # noqa: F821 - ): + + # Avoid calling array_type("cupy") repeatidely in the any check + array_type_cupy = array_type("cupy") + if any(isinstance(x, array_type_cupy) for x in scalars_or_arrays): import cupy as cp arrays = [asarray(x, xp=cp) for x in scalars_or_arrays]