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

Function test_align_dataset

xarray/tests/test_units.py:587–664  ·  view source on GitHub ↗
(value, unit, variant, error, dtype)

Source from the content-addressed store, hash-verified

585)
586@pytest.mark.parametrize("value", (10, dtypes.NA))
587def test_align_dataset(value, unit, variant, error, dtype):
588 if variant == "coords" and (
589 value != dtypes.NA or isinstance(unit, unit_registry.Unit)
590 ):
591 pytest.xfail(
592 reason=(
593 "fill_value is used for both data variables and coords. "
594 "See https://github.com/pydata/xarray/issues/4165"
595 )
596 )
597
598 fill_value = dtypes.get_fill_value(dtype) if value == dtypes.NA else value
599
600 original_unit = unit_registry.m
601
602 variants = {
603 "data": ((original_unit, unit), (1, 1), (1, 1)),
604 "dims": ((1, 1), (original_unit, unit), (1, 1)),
605 "coords": ((1, 1), (1, 1), (original_unit, unit)),
606 }
607 (
608 (data_unit1, data_unit2),
609 (dim_unit1, dim_unit2),
610 (coord_unit1, coord_unit2),
611 ) = variants[variant]
612
613 array1 = np.linspace(0, 10, 2 * 5).reshape(2, 5).astype(dtype) * data_unit1
614 array2 = np.linspace(0, 10, 2 * 5).reshape(2, 5).astype(dtype) * data_unit2
615
616 x = np.arange(2) * dim_unit1
617 y1 = np.arange(5) * dim_unit1
618 y2 = np.arange(2, 7) * dim_unit2
619
620 u1 = np.array([3, 5, 7, 8, 9]) * coord_unit1
621 u2 = np.array([7, 8, 9, 11, 13]) * coord_unit2
622
623 coords1 = {"x": x, "y": y1}
624 coords2 = {"x": x, "y": y2}
625 if variant == "coords":
626 coords1["u"] = ("y", u1)
627 coords2["u"] = ("y", u2)
628
629 ds1 = xr.Dataset(data_vars={"a": (("x", "y"), array1)}, coords=coords1)
630 ds2 = xr.Dataset(data_vars={"a": (("x", "y"), array2)}, coords=coords2)
631
632 fill_value = fill_value * data_unit2
633 func = function(xr.align, join="outer", fill_value=fill_value)
634 if error is not None and (value != dtypes.NA or isinstance(fill_value, Quantity)):
635 with pytest.raises(error):
636 func(ds1, ds2)
637
638 return
639
640 stripped_kwargs = {
641 key: strip_units(
642 convert_units(value, {None: data_unit1 if data_unit2 != 1 else None})
643 )
644 for key, value in func.kwargs.items()

Callers

nothing calls this directly

Calls 12

assert_allcloseFunction · 0.90
functionClass · 0.85
strip_unitsFunction · 0.85
convert_unitsFunction · 0.85
extract_unitsFunction · 0.85
attach_unitsFunction · 0.85
assert_units_equalFunction · 0.85
linspaceMethod · 0.80
arangeMethod · 0.80
itemsMethod · 0.80
funcFunction · 0.70
astypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…