(variant, unit, error, dtype)
| 1000 | ), |
| 1001 | ) |
| 1002 | def test_concat_dataset(variant, unit, error, dtype): |
| 1003 | original_unit = unit_registry.m |
| 1004 | |
| 1005 | variants = { |
| 1006 | "data": ((original_unit, unit), (1, 1), (1, 1)), |
| 1007 | "dims": ((1, 1), (original_unit, unit), (1, 1)), |
| 1008 | "coords": ((1, 1), (1, 1), (original_unit, unit)), |
| 1009 | } |
| 1010 | ( |
| 1011 | (data_unit1, data_unit2), |
| 1012 | (dim_unit1, dim_unit2), |
| 1013 | (coord_unit1, coord_unit2), |
| 1014 | ) = variants[variant] |
| 1015 | |
| 1016 | array1 = np.linspace(0, 5, 10).astype(dtype) * data_unit1 |
| 1017 | array2 = np.linspace(-5, 0, 5).astype(dtype) * data_unit2 |
| 1018 | |
| 1019 | x1 = np.arange(5, 15) * dim_unit1 |
| 1020 | x2 = np.arange(5) * dim_unit2 |
| 1021 | |
| 1022 | u1 = np.linspace(1, 2, 10).astype(dtype) * coord_unit1 |
| 1023 | u2 = np.linspace(0, 1, 5).astype(dtype) * coord_unit2 |
| 1024 | |
| 1025 | ds1 = xr.Dataset(data_vars={"a": ("x", array1)}, coords={"x": x1, "u": ("x", u1)}) |
| 1026 | ds2 = xr.Dataset(data_vars={"a": ("x", array2)}, coords={"x": x2, "u": ("x", u2)}) |
| 1027 | |
| 1028 | if error is not None: |
| 1029 | with pytest.raises(error): |
| 1030 | xr.concat([ds1, ds2], dim="x") |
| 1031 | |
| 1032 | return |
| 1033 | |
| 1034 | units = extract_units(ds1) |
| 1035 | expected = attach_units( |
| 1036 | xr.concat([strip_units(ds1), strip_units(convert_units(ds2, units))], dim="x"), |
| 1037 | units, |
| 1038 | ) |
| 1039 | actual = xr.concat([ds1, ds2], dim="x") |
| 1040 | |
| 1041 | assert_units_equal(expected, actual) |
| 1042 | assert_identical(expected, actual) |
| 1043 | |
| 1044 | |
| 1045 | @pytest.mark.parametrize( |
nothing calls this directly
no test coverage detected
searching dependent graphs…