MCPcopy
hub / github.com/pydata/xarray / test_combine_nested

Function test_combine_nested

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

Source from the content-addressed store, hash-verified

826 ),
827)
828def test_combine_nested(variant, unit, error, dtype):
829 original_unit = unit_registry.m
830
831 variants = {
832 "data": ((original_unit, unit), (1, 1), (1, 1)),
833 "dims": ((1, 1), (original_unit, unit), (1, 1)),
834 "coords": ((1, 1), (1, 1), (original_unit, unit)),
835 }
836 (
837 (data_unit1, data_unit2),
838 (dim_unit1, dim_unit2),
839 (coord_unit1, coord_unit2),
840 ) = variants[variant]
841
842 array1 = np.zeros(shape=(2, 3), dtype=dtype) * data_unit1
843 array2 = np.zeros(shape=(2, 3), dtype=dtype) * data_unit1
844
845 x = np.arange(1, 4) * 10 * dim_unit1
846 y = np.arange(2) * dim_unit1
847 z = np.arange(3) * coord_unit1
848
849 ds1 = xr.Dataset(
850 data_vars={"a": (("y", "x"), array1), "b": (("y", "x"), array2)},
851 coords={"x": x, "y": y, "z": ("x", z)},
852 )
853 ds2 = xr.Dataset(
854 data_vars={
855 "a": (("y", "x"), np.ones_like(array1) * data_unit2),
856 "b": (("y", "x"), np.ones_like(array2) * data_unit2),
857 },
858 coords={
859 "x": np.arange(3) * dim_unit2,
860 "y": np.arange(2, 4) * dim_unit2,
861 "z": ("x", np.arange(-3, 0) * coord_unit2),
862 },
863 )
864 ds3 = xr.Dataset(
865 data_vars={
866 "a": (("y", "x"), np.full_like(array1, fill_value=np.nan) * data_unit2),
867 "b": (("y", "x"), np.full_like(array2, fill_value=np.nan) * data_unit2),
868 },
869 coords={
870 "x": np.arange(3, 6) * dim_unit2,
871 "y": np.arange(4, 6) * dim_unit2,
872 "z": ("x", np.arange(3, 6) * coord_unit2),
873 },
874 )
875 ds4 = xr.Dataset(
876 data_vars={
877 "a": (("y", "x"), -1 * np.ones_like(array1) * data_unit2),
878 "b": (("y", "x"), -1 * np.ones_like(array2) * data_unit2),
879 },
880 coords={
881 "x": np.arange(6, 9) * dim_unit2,
882 "y": np.arange(6, 8) * dim_unit2,
883 "z": ("x", np.arange(6, 9) * coord_unit2),
884 },
885 )

Callers

nothing calls this directly

Calls 9

assert_identicalFunction · 0.90
functionClass · 0.85
extract_unitsFunction · 0.85
strip_unitsFunction · 0.85
convert_unitsFunction · 0.85
attach_unitsFunction · 0.85
assert_units_equalFunction · 0.85
arangeMethod · 0.80
funcFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…