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

Method test_combine_first

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

Source from the content-addressed store, hash-verified

4495 ),
4496 )
4497 def test_combine_first(self, variant, unit, error, dtype):
4498 variants = {
4499 "data": (unit_registry.m, unit, 1, 1),
4500 "dims": (1, 1, unit_registry.m, unit),
4501 }
4502 data_unit, other_data_unit, dims_unit, other_dims_unit = variants[variant]
4503
4504 array1 = (
4505 create_nan_array([1.4, np.nan, 2.3, np.nan, np.nan, 9.1], dtype) * data_unit
4506 )
4507 array2 = (
4508 create_nan_array([4.3, 9.8, 7.5, np.nan, 8.2, np.nan], dtype) * data_unit
4509 )
4510 x = np.arange(len(array1)) * dims_unit
4511 ds = xr.Dataset(
4512 data_vars={"a": ("x", array1), "b": ("x", array2)},
4513 coords={"x": x},
4514 )
4515 units = extract_units(ds)
4516
4517 other_array1 = np.ones_like(array1) * other_data_unit
4518 other_array2 = np.full_like(array2, fill_value=-1) * other_data_unit
4519 other_x = (np.arange(array1.shape[0]) + 5) * other_dims_unit
4520 other = xr.Dataset(
4521 data_vars={"a": ("x", other_array1), "b": ("x", other_array2)},
4522 coords={"x": other_x},
4523 )
4524
4525 if error is not None:
4526 with pytest.raises(error):
4527 ds.combine_first(other)
4528
4529 return
4530
4531 expected = attach_units(
4532 strip_units(ds).combine_first(strip_units(convert_units(other, units))),
4533 units,
4534 )
4535 actual = ds.combine_first(other)
4536
4537 assert_units_equal(expected, actual)
4538 assert_equal(expected, actual)
4539
4540 @pytest.mark.parametrize(
4541 "unit",

Callers

nothing calls this directly

Calls 9

combine_firstMethod · 0.95
assert_equalFunction · 0.90
create_nan_arrayFunction · 0.85
extract_unitsFunction · 0.85
attach_unitsFunction · 0.85
strip_unitsFunction · 0.85
convert_unitsFunction · 0.85
assert_units_equalFunction · 0.85
arangeMethod · 0.80

Tested by

no test coverage detected