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

Method test_1d_math

xarray/tests/test_units.py:1925–1956  ·  view source on GitHub ↗
(self, func, unit, error, dtype)

Source from the content-addressed store, hash-verified

1923 ids=repr,
1924 )
1925 def test_1d_math(self, func, unit, error, dtype):
1926 base_unit = unit_registry.m
1927 array = np.arange(5).astype(dtype) * base_unit
1928 variable = xr.Variable("x", array)
1929
1930 values = np.ones(5)
1931 y = values * unit
1932
1933 if error is not None and func.name in ("sum", "commutative_sum"):
1934 with pytest.raises(error):
1935 func(variable, y)
1936
1937 return
1938
1939 units = extract_units(func(array, y))
1940 if all(compatible_mappings(units, extract_units(y)).values()):
1941 converted_y = convert_units(y, units)
1942 else:
1943 converted_y = y
1944
1945 if all(compatible_mappings(units, extract_units(variable)).values()):
1946 converted_variable = convert_units(variable, units)
1947 else:
1948 converted_variable = variable
1949
1950 expected = attach_units(
1951 func(strip_units(converted_variable), strip_units(converted_y)), units
1952 )
1953 actual = func(variable, y)
1954
1955 assert_units_equal(expected, actual)
1956 assert_allclose(expected, actual)
1957
1958 @pytest.mark.parametrize(
1959 "unit,error",

Callers

nothing calls this directly

Calls 11

assert_allcloseFunction · 0.90
extract_unitsFunction · 0.85
compatible_mappingsFunction · 0.85
convert_unitsFunction · 0.85
attach_unitsFunction · 0.85
strip_unitsFunction · 0.85
assert_units_equalFunction · 0.85
arangeMethod · 0.80
funcFunction · 0.70
astypeMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected