MCPcopy Index your code
hub / github.com/pydata/xarray / test_loc

Method test_loc

xarray/tests/test_units.py:3360–3384  ·  view source on GitHub ↗
(self, raw_values, unit, error, dtype)

Source from the content-addressed store, hash-verified

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(

Callers

nothing calls this directly

Calls 10

assert_identicalFunction · 0.90
attach_unitsFunction · 0.85
strip_unitsFunction · 0.85
convert_unitsFunction · 0.85
extract_unitsFunction · 0.85
assert_units_equalFunction · 0.85
linspaceMethod · 0.80
arangeMethod · 0.80
checkMethod · 0.80
astypeMethod · 0.45

Tested by

no test coverage detected