(variant, unit, error, dtype)
| 749 | "ignore:.*the default value for coords will change:FutureWarning" |
| 750 | ) |
| 751 | def test_combine_by_coords(variant, unit, error, dtype): |
| 752 | original_unit = unit_registry.m |
| 753 | |
| 754 | variants = { |
| 755 | "data": ((original_unit, unit), (1, 1), (1, 1)), |
| 756 | "dims": ((1, 1), (original_unit, unit), (1, 1)), |
| 757 | "coords": ((1, 1), (1, 1), (original_unit, unit)), |
| 758 | } |
| 759 | ( |
| 760 | (data_unit1, data_unit2), |
| 761 | (dim_unit1, dim_unit2), |
| 762 | (coord_unit1, coord_unit2), |
| 763 | ) = variants[variant] |
| 764 | |
| 765 | array1 = np.zeros(shape=(2, 3), dtype=dtype) * data_unit1 |
| 766 | array2 = np.zeros(shape=(2, 3), dtype=dtype) * data_unit1 |
| 767 | x = np.arange(1, 4) * 10 * dim_unit1 |
| 768 | y = np.arange(2) * dim_unit1 |
| 769 | u = np.arange(3) * coord_unit1 |
| 770 | |
| 771 | other_array1 = np.ones_like(array1) * data_unit2 |
| 772 | other_array2 = np.ones_like(array2) * data_unit2 |
| 773 | other_x = np.arange(1, 4) * 10 * dim_unit2 |
| 774 | other_y = np.arange(2, 4) * dim_unit2 |
| 775 | other_u = np.arange(3, 6) * coord_unit2 |
| 776 | |
| 777 | ds = xr.Dataset( |
| 778 | data_vars={"a": (("y", "x"), array1), "b": (("y", "x"), array2)}, |
| 779 | coords={"x": x, "y": y, "u": ("x", u)}, |
| 780 | ) |
| 781 | other = xr.Dataset( |
| 782 | data_vars={"a": (("y", "x"), other_array1), "b": (("y", "x"), other_array2)}, |
| 783 | coords={"x": other_x, "y": other_y, "u": ("x", other_u)}, |
| 784 | ) |
| 785 | |
| 786 | if error is not None: |
| 787 | with pytest.raises(error): |
| 788 | xr.combine_by_coords([ds, other], coords="different", compat="no_conflicts") |
| 789 | |
| 790 | return |
| 791 | |
| 792 | units = extract_units(ds) |
| 793 | expected = attach_units( |
| 794 | xr.combine_by_coords( |
| 795 | [strip_units(ds), strip_units(convert_units(other, units))] |
| 796 | ), |
| 797 | units, |
| 798 | ) |
| 799 | actual = xr.combine_by_coords([ds, other]) |
| 800 | |
| 801 | assert_units_equal(expected, actual) |
| 802 | assert_identical(expected, actual) |
| 803 | |
| 804 | |
| 805 | @pytest.mark.parametrize( |
nothing calls this directly
no test coverage detected
searching dependent graphs…