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

Method test_combine_first

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

Source from the content-addressed store, hash-verified

2974 ),
2975 )
2976 def test_combine_first(self, unit, error, dtype):
2977 array = np.zeros(shape=(2, 2), dtype=dtype) * unit_registry.m
2978 other_array = np.ones_like(array) * unit
2979
2980 data_array = xr.DataArray(
2981 data=array, coords={"x": ["a", "b"], "y": [-1, 0]}, dims=["x", "y"]
2982 )
2983 other = xr.DataArray(
2984 data=other_array, coords={"x": ["b", "c"], "y": [0, 1]}, dims=["x", "y"]
2985 )
2986
2987 if error is not None:
2988 with pytest.raises(error):
2989 data_array.combine_first(other)
2990
2991 return
2992
2993 units = extract_units(data_array)
2994 expected = attach_units(
2995 strip_units(data_array).combine_first(
2996 strip_units(convert_units(other, units))
2997 ),
2998 units,
2999 )
3000 actual = data_array.combine_first(other)
3001
3002 assert_units_equal(expected, actual)
3003 assert_identical(expected, actual)
3004
3005 @pytest.mark.parametrize(
3006 "unit",

Callers

nothing calls this directly

Calls 8

combine_firstMethod · 0.95
assert_identicalFunction · 0.90
extract_unitsFunction · 0.85
attach_unitsFunction · 0.85
strip_unitsFunction · 0.85
convert_unitsFunction · 0.85
assert_units_equalFunction · 0.85
combine_firstMethod · 0.45

Tested by

no test coverage detected