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

Method test_comparisons

xarray/tests/test_units.py:1795–1825  ·  view source on GitHub ↗
(self, func, unit, convert_data, dtype)

Source from the content-addressed store, hash-verified

1793 ids=repr,
1794 )
1795 def test_comparisons(self, func, unit, convert_data, dtype):
1796 array = np.linspace(0, 1, 9).astype(dtype)
1797 quantity1 = array * unit_registry.m
1798 variable = xr.Variable("x", quantity1)
1799
1800 if convert_data and is_compatible(unit_registry.m, unit):
1801 quantity2 = convert_units(array * unit_registry.m, {None: unit})
1802 else:
1803 quantity2 = array * unit
1804 other = xr.Variable("x", quantity2)
1805
1806 expected = func(
1807 strip_units(variable),
1808 strip_units(
1809 convert_units(other, extract_units(variable))
1810 if is_compatible(unit_registry.m, unit)
1811 else other
1812 ),
1813 )
1814 if func.name == "identical":
1815 expected &= extract_units(variable) == extract_units(other)
1816 else:
1817 expected &= all(
1818 compatible_mappings(
1819 extract_units(variable), extract_units(other)
1820 ).values()
1821 )
1822
1823 actual = func(variable, other)
1824
1825 assert expected == actual
1826
1827 @pytest.mark.parametrize(
1828 "unit",

Callers

nothing calls this directly

Calls 9

is_compatibleFunction · 0.85
convert_unitsFunction · 0.85
strip_unitsFunction · 0.85
extract_unitsFunction · 0.85
compatible_mappingsFunction · 0.85
linspaceMethod · 0.80
funcFunction · 0.70
astypeMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected