(self, func, variation, unit, dtype)
| 3034 | ids=repr, |
| 3035 | ) |
| 3036 | def test_comparisons(self, func, variation, unit, dtype): |
| 3037 | def is_compatible(a, b): |
| 3038 | a = a if a is not None else 1 |
| 3039 | b = b if b is not None else 1 |
| 3040 | quantity = np.arange(5) * a |
| 3041 | |
| 3042 | return a == b or quantity.check(b) |
| 3043 | |
| 3044 | data = np.linspace(0, 5, 10).astype(dtype) |
| 3045 | coord = np.arange(len(data)).astype(dtype) |
| 3046 | |
| 3047 | base_unit = unit_registry.m |
| 3048 | array = data * (base_unit if variation == "data" else 1) |
| 3049 | x = coord * (base_unit if variation == "dims" else 1) |
| 3050 | y = coord * (base_unit if variation == "coords" else 1) |
| 3051 | |
| 3052 | variations = { |
| 3053 | "data": (unit, 1, 1), |
| 3054 | "dims": (1, unit, 1), |
| 3055 | "coords": (1, 1, unit), |
| 3056 | } |
| 3057 | data_unit, dim_unit, coord_unit = variations[variation] |
| 3058 | |
| 3059 | data_array = xr.DataArray(data=array, coords={"x": x, "y": ("x", y)}, dims="x") |
| 3060 | |
| 3061 | other = attach_units( |
| 3062 | strip_units(data_array), {None: data_unit, "x": dim_unit, "y": coord_unit} |
| 3063 | ) |
| 3064 | |
| 3065 | units = extract_units(data_array) |
| 3066 | other_units = extract_units(other) |
| 3067 | |
| 3068 | equal_arrays = all( |
| 3069 | is_compatible(units[name], other_units[name]) for name in units.keys() |
| 3070 | ) and ( |
| 3071 | strip_units(data_array).equals( |
| 3072 | strip_units(convert_units(other, extract_units(data_array))) |
| 3073 | ) |
| 3074 | ) |
| 3075 | equal_units = units == other_units |
| 3076 | expected = equal_arrays and (func.name != "identical" or equal_units) |
| 3077 | |
| 3078 | actual = func(data_array, other) |
| 3079 | |
| 3080 | assert expected == actual |
| 3081 | |
| 3082 | @pytest.mark.parametrize( |
| 3083 | "unit", |
nothing calls this directly
no test coverage detected