(value, unit, variant, error, dtype)
| 585 | ) |
| 586 | @pytest.mark.parametrize("value", (10, dtypes.NA)) |
| 587 | def 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() |
nothing calls this directly
no test coverage detected
searching dependent graphs…