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

Method test_sel

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

Source from the content-addressed store, hash-verified

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(

Callers

nothing calls this directly

Calls 12

selMethod · 0.95
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
selMethod · 0.45

Tested by

no test coverage detected