Example #1
0
def test_ffill_bfill_dask(method):
    da, _ = make_interpolate_example_data((40, 40), 0.5)
    da = da.chunk({"x": 5})

    dask_method = getattr(da, method)
    numpy_method = getattr(da.compute(), method)
    # unchunked axis
    with raise_if_dask_computes():
        actual = dask_method("time")
    expected = numpy_method("time")
    assert_equal(actual, expected)

    # chunked axis
    with raise_if_dask_computes():
        actual = dask_method("x")
    expected = numpy_method("x")
    assert_equal(actual, expected)

    # with limit
    with raise_if_dask_computes():
        actual = dask_method("time", limit=3)
    expected = numpy_method("time", limit=3)
    assert_equal(actual, expected)

    # limit < axis size
    with pytest.raises(NotImplementedError):
        actual = dask_method("x", limit=2)

    # limit > axis size
    with raise_if_dask_computes():
        actual = dask_method("x", limit=41)
    expected = numpy_method("x", limit=41)
    assert_equal(actual, expected)
Example #2
0
def test_skipna_broadcast_weights_assignment_destination(
        a_rand_nan, b_rand_nan, weights_lonlat, metric):
    """Tests that 'assignment destination is read-only' is not raised
    https://github.com/xarray-contrib/xskillscore/issues/79"""
    with raise_if_dask_computes():
        metric(a_rand_nan,
               b_rand_nan, ["lat", "lon"],
               weights=weights_lonlat,
               skipna=True)
Example #3
0
def test_skipna_returns_same_value_as_dropped_pairwise_nans(
        a_1d_fixed_nan, b_1d_fixed_nan, metric):
    """Tests that DataArrays with pairwise nans return the same result
    as the same two with those nans dropped."""
    a_dropped, b_dropped, _ = drop_nans(a_1d_fixed_nan, b_1d_fixed_nan)
    with raise_if_dask_computes():
        res_with_nans = metric(a_1d_fixed_nan,
                               b_1d_fixed_nan,
                               "time",
                               skipna=True)
        res_dropped_nans = metric(a_dropped, b_dropped, "time")
    assert_allclose(res_with_nans, res_dropped_nans)
Example #4
0
def test_skipna_returns_nan_when_false(a_1d_fixed_nan, b_1d_fixed_nan, metric):
    """Tests that nan is returned if there's any nans in the time series
    and skipna is False."""
    with raise_if_dask_computes():
        res = metric(a_1d_fixed_nan, b_1d_fixed_nan, "time", skipna=False)
    assert np.isnan(res).all()
Example #5
0
def test_nan_skipna(a, b):
    # Randomly add some nans to a
    a = a.where(np.random.random(a.shape) < 0.5)
    with raise_if_dask_computes():
        pearson_r(a, b, dim="lat", skipna=True)