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

Method test_drop_sel

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

Source from the content-addressed store, hash-verified

4940 ),
4941 )
4942 def test_drop_sel(self, raw_values, unit, error, dtype):
4943 array1 = np.linspace(5, 10, 20).astype(dtype) * unit_registry.degK
4944 array2 = np.linspace(0, 5, 20).astype(dtype) * unit_registry.Pa
4945 x = np.arange(len(array1)) * unit_registry.m
4946
4947 ds = xr.Dataset(
4948 data_vars={
4949 "a": xr.DataArray(data=array1, dims="x"),
4950 "b": xr.DataArray(data=array2, dims="x"),
4951 },
4952 coords={"x": x},
4953 )
4954
4955 values = raw_values * unit
4956
4957 # TODO: if we choose dm as compatible unit, single value keys
4958 # can be found. Should we check that?
4959 if error is not None:
4960 with pytest.raises(error):
4961 ds.drop_sel(x=values)
4962
4963 return
4964
4965 expected = attach_units(
4966 strip_units(ds).drop_sel(
4967 x=strip_units(convert_units(values, {None: unit_registry.m}))
4968 ),
4969 extract_units(ds),
4970 )
4971 actual = ds.drop_sel(x=values)
4972
4973 assert_units_equal(expected, actual)
4974 assert_equal(expected, actual)
4975
4976 @pytest.mark.skip(reason="indexes don't support units")
4977 @pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 10

drop_selMethod · 0.95
assert_equalFunction · 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
astypeMethod · 0.45

Tested by

no test coverage detected