| 6010 | assert_identical(expected9, actual9) |
| 6011 | |
| 6012 | def test_where_other(self) -> None: |
| 6013 | ds = Dataset({"a": ("x", range(5))}, {"x": range(5)}) |
| 6014 | expected = Dataset({"a": ("x", [-1, -1, 2, 3, 4])}, {"x": range(5)}) |
| 6015 | actual = ds.where(ds > 1, -1) |
| 6016 | assert_equal(expected, actual) |
| 6017 | assert actual.a.dtype == int |
| 6018 | |
| 6019 | actual = ds.where(lambda x: x > 1, -1) |
| 6020 | assert_equal(expected, actual) |
| 6021 | |
| 6022 | actual = ds.where(ds > 1, other=-1, drop=True) |
| 6023 | expected_nodrop = ds.where(ds > 1, -1) |
| 6024 | _, expected = xr.align(actual, expected_nodrop, join="left") |
| 6025 | assert_equal(actual, expected) |
| 6026 | assert actual.a.dtype == int |
| 6027 | |
| 6028 | with pytest.raises(ValueError, match=r"cannot align .* are not equal"): |
| 6029 | ds.where(ds > 1, ds.isel(x=slice(3))) |
| 6030 | |
| 6031 | with pytest.raises(ValueError, match=r"exact match required"): |
| 6032 | ds.where(ds > 1, ds.assign(b=2)) |
| 6033 | |
| 6034 | def test_where_drop(self) -> None: |
| 6035 | # if drop=True |