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

Method test_broadcast_like

xarray/tests/test_units.py:3102–3140  ·  view source on GitHub ↗
(self, variant, unit, dtype)

Source from the content-addressed store, hash-verified

3100 ),
3101 )
3102 def test_broadcast_like(self, variant, unit, dtype):
3103 original_unit = unit_registry.m
3104
3105 variants = {
3106 "data": ((original_unit, unit), (1, 1), (1, 1)),
3107 "dims": ((1, 1), (original_unit, unit), (1, 1)),
3108 "coords": ((1, 1), (1, 1), (original_unit, unit)),
3109 }
3110 (
3111 (data_unit1, data_unit2),
3112 (dim_unit1, dim_unit2),
3113 (coord_unit1, coord_unit2),
3114 ) = variants[variant]
3115
3116 array1 = np.linspace(1, 2, 2 * 1).reshape(2, 1).astype(dtype) * data_unit1
3117 array2 = np.linspace(0, 1, 2 * 3).reshape(2, 3).astype(dtype) * data_unit2
3118
3119 x1 = np.arange(2) * dim_unit1
3120 x2 = np.arange(2) * dim_unit2
3121 y1 = np.array([0]) * dim_unit1
3122 y2 = np.arange(3) * dim_unit2
3123
3124 u1 = np.linspace(0, 1, 2) * coord_unit1
3125 u2 = np.linspace(0, 1, 2) * coord_unit2
3126
3127 arr1 = xr.DataArray(
3128 data=array1, coords={"x": x1, "y": y1, "u": ("x", u1)}, dims=("x", "y")
3129 )
3130 arr2 = xr.DataArray(
3131 data=array2, coords={"x": x2, "y": y2, "u": ("x", u2)}, dims=("x", "y")
3132 )
3133
3134 expected = attach_units(
3135 strip_units(arr1).broadcast_like(strip_units(arr2)), extract_units(arr1)
3136 )
3137 actual = arr1.broadcast_like(arr2)
3138
3139 assert_units_equal(expected, actual)
3140 assert_identical(expected, actual)
3141
3142 @pytest.mark.parametrize(
3143 "unit",

Callers

nothing calls this directly

Calls 10

broadcast_likeMethod · 0.95
assert_identicalFunction · 0.90
attach_unitsFunction · 0.85
strip_unitsFunction · 0.85
extract_unitsFunction · 0.85
assert_units_equalFunction · 0.85
linspaceMethod · 0.80
arangeMethod · 0.80
astypeMethod · 0.45
broadcast_likeMethod · 0.45

Tested by

no test coverage detected