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

Method test_comparison_operations

xarray/tests/test_units.py:2488–2517  ·  view source on GitHub ↗
(self, comparison, unit, error, dtype)

Source from the content-addressed store, hash-verified

2486 ),
2487 )
2488 def test_comparison_operations(self, comparison, unit, error, dtype):
2489 array = (
2490 np.array([10.1, 5.2, 6.5, 8.0, 21.3, 7.1, 1.3]).astype(dtype)
2491 * unit_registry.m
2492 )
2493 data_array = xr.DataArray(data=array)
2494
2495 value = 8
2496 to_compare_with = value * unit
2497
2498 # incompatible units are all not equal
2499 if error is not None and comparison is not operator.eq:
2500 with pytest.raises(error):
2501 comparison(array, to_compare_with)
2502
2503 with pytest.raises(error):
2504 comparison(data_array, to_compare_with)
2505
2506 return
2507
2508 actual = comparison(data_array, to_compare_with)
2509
2510 expected_units = {None: unit_registry.m if array.check(unit) else None}
2511 expected = array.check(unit) & comparison(
2512 strip_units(data_array),
2513 strip_units(convert_units(to_compare_with, expected_units)),
2514 )
2515
2516 assert_units_equal(expected, actual)
2517 assert_identical(expected, actual)
2518
2519 @pytest.mark.parametrize(
2520 "units,error",

Callers

nothing calls this directly

Calls 6

assert_identicalFunction · 0.90
strip_unitsFunction · 0.85
convert_unitsFunction · 0.85
assert_units_equalFunction · 0.85
checkMethod · 0.80
astypeMethod · 0.45

Tested by

no test coverage detected