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

Function test_concat_dataarray

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

Source from the content-addressed store, hash-verified

932 ),
933)
934def 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(

Callers

nothing calls this directly

Calls 10

assert_identicalFunction · 0.90
extract_unitsFunction · 0.85
attach_unitsFunction · 0.85
strip_unitsFunction · 0.85
convert_unitsFunction · 0.85
assert_units_equalFunction · 0.85
linspaceMethod · 0.80
arangeMethod · 0.80
astypeMethod · 0.45
concatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…