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

Method test_drop_sel

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

Source from the content-addressed store, hash-verified

3403 ),
3404 )
3405 def test_drop_sel(self, raw_values, unit, error, dtype):
3406 array = np.linspace(5, 10, 20).astype(dtype) * unit_registry.m
3407 x = np.arange(len(array)) * unit_registry.m
3408 data_array = xr.DataArray(data=array, coords={"x": x}, dims="x")
3409
3410 values = raw_values * unit
3411
3412 if error is not None and not (
3413 isinstance(raw_values, int | float) and x.check(unit)
3414 ):
3415 with pytest.raises(error):
3416 data_array.drop_sel(x=values)
3417
3418 return
3419
3420 expected = attach_units(
3421 strip_units(data_array).drop_sel(
3422 x=strip_units(convert_units(values, {None: x.units}))
3423 ),
3424 extract_units(data_array),
3425 )
3426 actual = data_array.drop_sel(x=values)
3427
3428 assert_units_equal(expected, actual)
3429 assert_identical(expected, actual)
3430
3431 @pytest.mark.parametrize("dim", ("x", "y", "z", "t", "all"))
3432 @pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 12

drop_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
drop_selMethod · 0.45

Tested by

no test coverage detected