MCPcopy
hub / github.com/pydata/xarray / test_sel

Method test_sel

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

Source from the content-addressed store, hash-verified

4887 ),
4888 )
4889 def test_sel(self, raw_values, unit, error, dtype):
4890 array1 = np.linspace(5, 10, 20).astype(dtype) * unit_registry.degK
4891 array2 = np.linspace(0, 5, 20).astype(dtype) * unit_registry.Pa
4892 x = np.arange(len(array1)) * unit_registry.m
4893
4894 ds = xr.Dataset(
4895 data_vars={
4896 "a": xr.DataArray(data=array1, dims="x"),
4897 "b": xr.DataArray(data=array2, dims="x"),
4898 },
4899 coords={"x": x},
4900 )
4901
4902 values = raw_values * unit
4903
4904 # TODO: if we choose dm as compatible unit, single value keys
4905 # can be found. Should we check that?
4906 if error is not None:
4907 with pytest.raises(error):
4908 ds.sel(x=values)
4909
4910 return
4911
4912 expected = attach_units(
4913 strip_units(ds).sel(
4914 x=strip_units(convert_units(values, {None: unit_registry.m}))
4915 ),
4916 extract_units(ds),
4917 )
4918 actual = ds.sel(x=values)
4919
4920 assert_units_equal(expected, actual)
4921 assert_equal(expected, actual)
4922
4923 @pytest.mark.skip(reason="indexes don't support units")
4924 @pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected