MCPcopy Index your code
hub / github.com/pydata/xarray / test_clip

Function test_clip

xarray/tests/test_dataarray.py:7433–7462  ·  view source on GitHub ↗
(da: DataArray)

Source from the content-addressed store, hash-verified

7431
7432
7433def test_clip(da: DataArray) -> None:
7434 with raise_if_dask_computes():
7435 result = da.clip(min=0.5)
7436 assert result.min() >= 0.5
7437
7438 result = da.clip(max=0.5)
7439 assert result.max() <= 0.5
7440
7441 result = da.clip(min=0.25, max=0.75)
7442 assert result.min() >= 0.25
7443 assert result.max() <= 0.75
7444
7445 with raise_if_dask_computes():
7446 result = da.clip(min=da.mean("x"), max=da.mean("a"))
7447 assert result.dims == da.dims
7448 assert_array_equal(
7449 result.data,
7450 np.clip(da.data, da.mean("x").data[:, :, np.newaxis], da.mean("a").data),
7451 )
7452
7453 with_nans = da.isel(time=[0, 1]).reindex_like(da)
7454 with raise_if_dask_computes():
7455 result = da.clip(min=da.mean("x"), max=da.mean("a"))
7456 result = da.clip(with_nans)
7457 # The values should be the same where there were NaNs.
7458 assert_array_equal(result.isel(time=[0, 1]), with_nans.isel(time=[0, 1]))
7459
7460 # Unclear whether we want this work, OK to adjust the test when we have decided.
7461 with pytest.raises(ValueError, match=r"cannot reindex or align along dimension.*"):
7462 result = da.clip(min=da.mean("x"), max=da.mean("a").isel(x=[0, 1]))
7463
7464
7465class TestDropDuplicates:

Callers

nothing calls this directly

Calls 7

raise_if_dask_computesFunction · 0.90
clipMethod · 0.45
minMethod · 0.45
maxMethod · 0.45
meanMethod · 0.45
reindex_likeMethod · 0.45
iselMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…