(da: DataArray)
| 7431 | |
| 7432 | |
| 7433 | def 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 | |
| 7465 | class TestDropDuplicates: |
nothing calls this directly
no test coverage detected
searching dependent graphs…