(self, raw_values, unit, error, dtype)
| 4887 | ), |
| 4888 | ) |
| 4889 | def test_sel(self, raw_values, unit, error, dtype): |
| 4890 | array1 = np.linspace(5, 10, 20).astype(dtype) * unit_registry.degK |
| 4891 | array2 = np.linspace(0, 5, 20).astype(dtype) * unit_registry.Pa |
| 4892 | x = np.arange(len(array1)) * unit_registry.m |
| 4893 | |
| 4894 | ds = xr.Dataset( |
| 4895 | data_vars={ |
| 4896 | "a": xr.DataArray(data=array1, dims="x"), |
| 4897 | "b": xr.DataArray(data=array2, dims="x"), |
| 4898 | }, |
| 4899 | coords={"x": x}, |
| 4900 | ) |
| 4901 | |
| 4902 | values = raw_values * unit |
| 4903 | |
| 4904 | # TODO: if we choose dm as compatible unit, single value keys |
| 4905 | # can be found. Should we check that? |
| 4906 | if error is not None: |
| 4907 | with pytest.raises(error): |
| 4908 | ds.sel(x=values) |
| 4909 | |
| 4910 | return |
| 4911 | |
| 4912 | expected = attach_units( |
| 4913 | strip_units(ds).sel( |
| 4914 | x=strip_units(convert_units(values, {None: unit_registry.m})) |
| 4915 | ), |
| 4916 | extract_units(ds), |
| 4917 | ) |
| 4918 | actual = ds.sel(x=values) |
| 4919 | |
| 4920 | assert_units_equal(expected, actual) |
| 4921 | assert_equal(expected, actual) |
| 4922 | |
| 4923 | @pytest.mark.skip(reason="indexes don't support units") |
| 4924 | @pytest.mark.parametrize( |
nothing calls this directly
no test coverage detected