(variant, unit, error, dtype)
| 932 | ), |
| 933 | ) |
| 934 | def test_concat_dataarray(variant, unit, error, dtype): |
| 935 | original_unit = unit_registry.m |
| 936 | |
| 937 | variants = { |
| 938 | "data": ((original_unit, unit), (1, 1), (1, 1)), |
| 939 | "dims": ((1, 1), (original_unit, unit), (1, 1)), |
| 940 | "coords": ((1, 1), (1, 1), (original_unit, unit)), |
| 941 | } |
| 942 | ( |
| 943 | (data_unit1, data_unit2), |
| 944 | (dim_unit1, dim_unit2), |
| 945 | (coord_unit1, coord_unit2), |
| 946 | ) = variants[variant] |
| 947 | |
| 948 | array1 = np.linspace(0, 5, 10).astype(dtype) * data_unit1 |
| 949 | array2 = np.linspace(-5, 0, 5).astype(dtype) * data_unit2 |
| 950 | |
| 951 | x1 = np.arange(5, 15) * dim_unit1 |
| 952 | x2 = np.arange(5) * dim_unit2 |
| 953 | |
| 954 | u1 = np.linspace(1, 2, 10).astype(dtype) * coord_unit1 |
| 955 | u2 = np.linspace(0, 1, 5).astype(dtype) * coord_unit2 |
| 956 | |
| 957 | arr1 = xr.DataArray(data=array1, coords={"x": x1, "u": ("x", u1)}, dims="x") |
| 958 | arr2 = xr.DataArray(data=array2, coords={"x": x2, "u": ("x", u2)}, dims="x") |
| 959 | |
| 960 | if error is not None: |
| 961 | with pytest.raises(error): |
| 962 | xr.concat([arr1, arr2], dim="x") |
| 963 | |
| 964 | return |
| 965 | |
| 966 | units = extract_units(arr1) |
| 967 | expected = attach_units( |
| 968 | xr.concat( |
| 969 | [strip_units(arr1), strip_units(convert_units(arr2, units))], dim="x" |
| 970 | ), |
| 971 | units, |
| 972 | ) |
| 973 | actual = xr.concat([arr1, arr2], dim="x") |
| 974 | |
| 975 | assert_units_equal(expected, actual) |
| 976 | assert_identical(expected, actual) |
| 977 | |
| 978 | |
| 979 | @pytest.mark.parametrize( |
nothing calls this directly
no test coverage detected
searching dependent graphs…