(self, raw_values, unit, error, dtype)
| 3358 | ), |
| 3359 | ) |
| 3360 | def test_loc(self, raw_values, unit, error, dtype): |
| 3361 | array = np.linspace(5, 10, 20).astype(dtype) * unit_registry.m |
| 3362 | x = np.arange(len(array)) * unit_registry.m |
| 3363 | data_array = xr.DataArray(data=array, coords={"x": x}, dims="x") |
| 3364 | |
| 3365 | values = raw_values * unit |
| 3366 | |
| 3367 | if error is not None and not ( |
| 3368 | isinstance(raw_values, int | float) and x.check(unit) |
| 3369 | ): |
| 3370 | with pytest.raises(error): |
| 3371 | data_array.loc[{"x": values}] |
| 3372 | |
| 3373 | return |
| 3374 | |
| 3375 | expected = attach_units( |
| 3376 | strip_units(data_array).loc[ |
| 3377 | {"x": strip_units(convert_units(values, {None: array.units}))} |
| 3378 | ], |
| 3379 | extract_units(data_array), |
| 3380 | ) |
| 3381 | actual = data_array.loc[{"x": values}] |
| 3382 | |
| 3383 | assert_units_equal(expected, actual) |
| 3384 | assert_identical(expected, actual) |
| 3385 | |
| 3386 | @pytest.mark.skip(reason="indexes don't support units") |
| 3387 | @pytest.mark.parametrize( |
nothing calls this directly
no test coverage detected