@@ -271,6 +271,8 @@ def xp_assert_close(
271271 Notes
272272 -----
273273 The default `atol` and `rtol` differ from `xp.all(xpx.isclose(a, b))`.
274+
275+ Array arguments to `atol` and `rtol` must be valid input to :py:func:`float`.
274276 """
275277 actual , desired , xp = _check_ns_shape_dtype (
276278 actual , desired , check_dtype , check_shape , check_scalar
@@ -286,21 +288,19 @@ def xp_assert_close(
286288 rtol = xp .finfo (actual .dtype ).eps ** 0.5 * 4
287289 else :
288290 rtol = 1e-7
291+ else :
292+ rtol = float (rtol )
289293
290- if hasattr (atol , "ndim" ) and atol .ndim == 0 : # pyright: ignore[reportAttributeAccessIssue]
291- atol = cast (Array , as_numpy_array (cast (Array , atol ), xp = xp )) # pyright: ignore[reportInvalidCast]
292-
293- if hasattr (rtol , "ndim" ) and rtol .ndim == 0 : # pyright: ignore[reportAttributeAccessIssue,reportOptionalMemberAccess]
294- rtol = cast (Array , as_numpy_array (cast (Array , rtol ), xp = xp )) # pyright: ignore[reportInvalidCast]
294+ atol = float (atol )
295295
296296 actual_np = as_numpy_array (actual , xp = xp )
297297 desired_np = as_numpy_array (desired , xp = xp )
298- np .testing .assert_allclose ( # pyright: ignore[reportCallIssue] # pyrefly: ignore[no-matching-overload]
298+ np .testing .assert_allclose ( # pyright: ignore[reportCallIssue]
299299 actual_np ,
300300 desired_np ,
301301 # https://github.com/numpy/numpy/issues/31449
302302 rtol = rtol , # type: ignore[arg-type] # pyright: ignore[reportArgumentType]
303- atol = atol , # type: ignore[arg-type] # pyright: ignore[reportArgumentType]
303+ atol = atol ,
304304 equal_nan = equal_nan ,
305305 err_msg = err_msg ,
306306 verbose = verbose ,
0 commit comments