(self, raw_values, unit, error, dtype)
| 3313 | ), |
| 3314 | ) |
| 3315 | def test_sel(self, raw_values, unit, error, dtype): |
| 3316 | array = np.linspace(5, 10, 20).astype(dtype) * unit_registry.m |
| 3317 | x = np.arange(len(array)) * unit_registry.m |
| 3318 | data_array = xr.DataArray(data=array, coords={"x": x}, dims="x") |
| 3319 | |
| 3320 | values = raw_values * unit |
| 3321 | |
| 3322 | if error is not None and not ( |
| 3323 | isinstance(raw_values, int | float) and x.check(unit) |
| 3324 | ): |
| 3325 | with pytest.raises(error): |
| 3326 | data_array.sel(x=values) |
| 3327 | |
| 3328 | return |
| 3329 | |
| 3330 | expected = attach_units( |
| 3331 | strip_units(data_array).sel( |
| 3332 | x=strip_units(convert_units(values, {None: array.units})) |
| 3333 | ), |
| 3334 | extract_units(data_array), |
| 3335 | ) |
| 3336 | actual = data_array.sel(x=values) |
| 3337 | |
| 3338 | assert_units_equal(expected, actual) |
| 3339 | assert_identical(expected, actual) |
| 3340 | |
| 3341 | @pytest.mark.skip(reason="indexes don't support units") |
| 3342 | @pytest.mark.parametrize( |
nothing calls this directly
no test coverage detected