Repository: scipy/scipy
File: scipy/stats/tests/test_quantile.py (Python)

Code before:
@make_xp_test_case(_xp_searchsorted)
class Test_XPSearchsorted:
    @pytest.mark.parametrize('side', ['left', 'right'])
    @pytest.mark.parametrize('ties', [False, True])
    @pytest.mark.parametrize('shape', [1, 2, 10, 11, 1000, 10001, (2, 10), (2, 3, 11)])
    @pytest.mark.parametrize('nans', [False, True])
    def test_nd(self, side, ties, shape, nans, xp):
        rng = np.random.default_rng(945298725498274853)
        if ties:
            x = rng.integers(5, size=shape)
        else:
            x = rng.random(shape)
        # float32 is to accommodate JAX - nextafter with `float64` is too small?
        x = np.asarray(x, dtype=np.float32)
        xr = np.nextafter(x, np.inf)
        xl = np.nextafter(x, -np.inf)
        x_ = np.asarray([-np.inf, np.inf])
        x_ = np.broadcast_to(x_, x.shape[:-1] + (2,))
        y = rng.permuted(np.concatenate((xl, x, xr, x_), axis=-1), axis=-1)
        if nans:
            # all elements of a slice are NaN and side='right',
            # _xp_searchsorted has a different convention
            mask = rng.random(shape) < 0.1
            x[mask] = np.nan
        x = np.sort(x, axis=-1)
        x, y = np.astype(x, np.float64), np.astype(y, np.float64)
        ref = xp.asarray(np_searchsorted(x, y, side=side))
        x, y = xp.asarray(x), xp.asarray(y)
        res = _xp_searchsorted(x, y, side=side)
        xp_assert_equal(res, ref)


Review comment (bug):
This should be all it takes to resolve CI failures, so I'll wait for something else to commit. Could use `astype` method, but I'd prefer to use something that's in the standard, and I don't want to use `array_namespace`.
```suggestion
        x, y = np.asarray(x, dtype=np.float64), np.asarray(y, dtype=np.float64)
```

Code after:
@make_xp_test_case(_xp_searchsorted)
class Test_XPSearchsorted:
    @pytest.mark.parametrize('side', ['left', 'right'])
    @pytest.mark.parametrize('ties', [False, True])
    @pytest.mark.parametrize('shape', [1, 2, 10, 11, 1000, 10001, (2, 10), (2, 3, 11)])
    @pytest.mark.parametrize('nans', [False, True])
    def test_nd(self, side, ties, shape, nans, xp):
        rng = np.random.default_rng(945298725498274853)
        if ties:
            x = rng.integers(5, size=shape)
        else:
            x = rng.random(shape)
        # float32 is to accommodate JAX - nextafter with `float64` is too small?
        x = np.asarray(x, dtype=np.float32)
        xr = np.nextafter(x, np.inf)
        xl = np.nextafter(x, -np.inf)
        x_ = np.asarray([-np.inf, np.inf])
        x_ = np.broadcast_to(x_, x.shape[:-1] + (2,))
        y = rng.permuted(np.concatenate((xl, x, xr, x_), axis=-1), axis=-1)
        if nans:
            # all elements of a slice are NaN and side='right',
            # _xp_searchsorted has a different convention
            mask = rng.random(shape) < 0.1
            x[mask] = np.nan
        x = np.sort(x, axis=-1)
        x, y = np.asarray(x, dtype=np.float64), np.asarray(y, dtype=np.float64)
        ref = xp.asarray(np_searchsorted(x, y, side=side))
        x, y = xp.asarray(x), xp.asarray(y)
        res = _xp_searchsorted(x, y, side=side)
        xp_assert_equal(res, ref)