Пример #1
0
def test_interpolate_multiindex_raises():
    data = np.random.randn(2, 3)
    data[1, 1] = np.nan
    da = xr.DataArray(data, coords=[('x', ['a', 'b']), ('y', [0, 1, 2])])
    das = da.stack(z=('x', 'y'))
    with raises_regex(TypeError, 'Index must be castable to float64'):
        das.interpolate_na(dim='z')
Пример #2
0
def test_interpolate_multiindex_raises():
    data = np.random.randn(2, 3)
    data[1, 1] = np.nan
    da = xr.DataArray(data, coords=[("x", ["a", "b"]), ("y", [0, 1, 2])])
    das = da.stack(z=("x", "y"))
    with raises_regex(TypeError, "Index 'z' must be castable to float64"):
        das.interpolate_na(dim="z")
Пример #3
0
def test_interpolate_multiindex_raises():
    data = np.random.randn(2, 3)
    data[1, 1] = np.nan
    da = xr.DataArray(data, coords=[('x', ['a', 'b']), ('y', [0, 1, 2])])
    das = da.stack(z=('x', 'y'))
    with raises_regex(TypeError, 'Index must be castable to float64'):
        das.interpolate_na(dim='z')
Пример #4
0
def test_interpolate_na_max_gap_errors(da_time):
    with raises_regex(NotImplementedError,
                      "max_gap not implemented for unlabeled coordinates"):
        da_time.interpolate_na("t", max_gap=1)

    with raises_regex(ValueError, "max_gap must be a scalar."):
        da_time.interpolate_na("t", max_gap=(1, ))

    da_time["t"] = pd.date_range("2001-01-01", freq="H", periods=11)
    with raises_regex(TypeError, "Expected value of type str"):
        da_time.interpolate_na("t", max_gap=1)

    with raises_regex(TypeError, "Expected integer or floating point"):
        da_time.interpolate_na("t", max_gap="1H", use_coordinate=False)

    with raises_regex(ValueError, "Could not convert 'huh' to timedelta64"):
        da_time.interpolate_na("t", max_gap="huh")
Пример #5
0
def test_weighted_non_DataArray_weights(as_dataset):

    data = DataArray([1, 2])
    if as_dataset:
        data = data.to_dataset(name="data")

    with raises_regex(ValueError, "`weights` must be a DataArray"):
        data.weighted([1, 2])
Пример #6
0
def test_interpolate_2d_coord_raises():
    coords = {'x': xr.Variable(('a', 'b'), np.arange(6).reshape(2, 3)),
              'y': xr.Variable(('a', 'b'), np.arange(6).reshape(2, 3)) * 2}

    data = np.random.randn(2, 3)
    data[1, 1] = np.nan
    da = xr.DataArray(data, dims=('a', 'b'), coords=coords)
    with raises_regex(ValueError, 'interpolation must be 1D'):
        da.interpolate_na(dim='a', use_coordinate='x')
Пример #7
0
def test_interpolate_2d_coord_raises():
    coords = {'x': xr.Variable(('a', 'b'), np.arange(6).reshape(2, 3)),
              'y': xr.Variable(('a', 'b'), np.arange(6).reshape(2, 3)) * 2}

    data = np.random.randn(2, 3)
    data[1, 1] = np.nan
    da = xr.DataArray(data, dims=('a', 'b'), coords=coords)
    with raises_regex(ValueError, 'interpolation must be 1D'):
        da.interpolate_na(dim='a', use_coordinate='x')
Пример #8
0
def test_interpolate_2d_coord_raises():
    coords = {
        "x": xr.Variable(("a", "b"), np.arange(6).reshape(2, 3)),
        "y": xr.Variable(("a", "b"), np.arange(6).reshape(2, 3)) * 2,
    }

    data = np.random.randn(2, 3)
    data[1, 1] = np.nan
    da = xr.DataArray(data, dims=("a", "b"), coords=coords)
    with raises_regex(ValueError, "interpolation must be 1D"):
        da.interpolate_na(dim="a", use_coordinate="x")
Пример #9
0
def test_interpolate_unsorted_index_raises():
    vals = np.array([1, 2, 3], dtype=np.float64)
    expected = xr.DataArray(vals, dims='x', coords={'x': [2, 1, 3]})
    with raises_regex(ValueError, 'Index must be monotonicly increasing'):
        expected.interpolate_na(dim='x', method='index')
Пример #10
0
def test_interpolate_dask_raises_for_invalid_chunk_dim():
    da, _ = make_interpolate_example_data((40, 40), 0.5)
    da = da.chunk({"time": 5})
    # this checks for ValueError in dask.array.apply_gufunc
    with raises_regex(ValueError, "consists of multiple chunks"):
        da.interpolate_na("time")
Пример #11
0
def test_interpolate_duplicate_values_raises():
    data = np.random.randn(2, 3)
    da = xr.DataArray(data, coords=[("x", ["a", "a"]), ("y", [0, 1, 2])])
    with raises_regex(ValueError, "Index 'x' has duplicate values"):
        da.interpolate_na(dim="x", method="foo")
Пример #12
0
def test_interpolate_no_dim_raises():
    da = xr.DataArray(np.array([1, 2, np.nan, 5], dtype=np.float64), dims='x')
    with raises_regex(NotImplementedError, 'dim is a required argument'):
        da.interpolate_na(method='linear')
Пример #13
0
def test_interpolate_dask_raises_for_invalid_chunk_dim():
    da, _ = make_interpolate_example_data((40, 40), 0.5)
    da = da.chunk({'time': 5})
    with raises_regex(ValueError, "dask='parallelized' consists of multiple"):
        da.interpolate_na('time')
Пример #14
0
def test_interpolate_invalid_interpolator_raises():
    da = xr.DataArray(np.array([1, 2, np.nan, 5], dtype=np.float64), dims='x')
    with raises_regex(ValueError, 'not a valid'):
        da.interpolate_na(dim='x', method='foo')
Пример #15
0
def test_interpolate_no_dim_raises():
    da = xr.DataArray(np.array([1, 2, np.nan, 5], dtype=np.float64), dims='x')
    with raises_regex(NotImplementedError, 'dim is a required argument'):
        da.interpolate_na(method='linear')
Пример #16
0
def test_interpolate_unsorted_index_raises():
    vals = np.array([1, 2, 3], dtype=np.float64)
    expected = xr.DataArray(vals, dims="x", coords={"x": [2, 1, 3]})
    with raises_regex(ValueError,
                      "Index 'x' must be monotonically increasing"):
        expected.interpolate_na(dim="x", method="index")
Пример #17
0
def test_interpolate_invalid_interpolator_raises():
    da = xr.DataArray(np.array([1, 2, np.nan, 5], dtype=np.float64), dims='x')
    with raises_regex(ValueError, 'not a valid'):
        da.interpolate_na(dim='x', method='foo')
Пример #18
0
def test_interpolate_invalid_interpolator_raises():
    da = xr.DataArray(np.array([1, 2, np.nan, 5], dtype=np.float64), dims="x")
    with raises_regex(ValueError, "not a valid"):
        da.interpolate_na(dim="x", method="foo")
Пример #19
0
def test_interpolate_dask_raises_for_invalid_chunk_dim():
    da, _ = make_interpolate_example_data((40, 40), 0.5)
    da = da.chunk({'time': 5})
    with raises_regex(ValueError, "dask='parallelized' consists of multiple"):
        da.interpolate_na('time')
Пример #20
0
def test_interpolate_unsorted_index_raises():
    vals = np.array([1, 2, 3], dtype=np.float64)
    expected = xr.DataArray(vals, dims='x', coords={'x': [2, 1, 3]})
    with raises_regex(ValueError, 'Index must be monotonicly increasing'):
        expected.interpolate_na(dim='x', method='index')