@@ -683,7 +683,7 @@ def test_nested_combine_mixed_datasets_arrays(self):
683
683
Dataset ({"x" : [2 , 3 ]}),
684
684
]
685
685
with pytest .raises (
686
- ValueError , match = r "Can't combine datasets with unnamed arrays. "
686
+ ValueError , match = "Can't automatically combine unnamed dataarrays with "
687
687
):
688
688
combine_nested (objs , "x" )
689
689
@@ -1034,15 +1034,19 @@ def test_combine_by_coords_incomplete_hypercube(self):
1034
1034
combine_by_coords ([x1 , x2 , x3 ], fill_value = None )
1035
1035
1036
1036
1037
- class TestCombineMixedObjectsbyCoords :
1038
- def test_combine_by_coords_mixed_unnamed_dataarrays (self ):
1037
+ class TestCombineMixedObjects :
1038
+ def test_combine_unnamed_named_dataarrays (self ):
1039
1039
named_da = DataArray (name = "a" , data = [1.0 , 2.0 ], coords = {"x" : [0 , 1 ]}, dims = "x" )
1040
1040
unnamed_da = DataArray (data = [3.0 , 4.0 ], coords = {"x" : [2 , 3 ]}, dims = "x" )
1041
1041
1042
1042
with pytest .raises (
1043
1043
ValueError , match = "Can't automatically combine unnamed dataarrays with"
1044
1044
):
1045
1045
combine_by_coords ([named_da , unnamed_da ])
1046
+ with pytest .raises (
1047
+ ValueError , match = "Can't automatically combine unnamed dataarrays with"
1048
+ ):
1049
+ combine_nested ([named_da , unnamed_da ], concat_dim = "x" )
1046
1050
1047
1051
da = DataArray ([0 , 1 ], dims = "x" , coords = ({"x" : [0 , 1 ]}))
1048
1052
ds = Dataset ({"x" : [2 , 3 ]})
@@ -1051,49 +1055,70 @@ def test_combine_by_coords_mixed_unnamed_dataarrays(self):
1051
1055
match = "Can't automatically combine unnamed dataarrays with" ,
1052
1056
):
1053
1057
combine_by_coords ([da , ds ])
1058
+ with pytest .raises (
1059
+ ValueError ,
1060
+ match = "Can't automatically combine unnamed dataarrays with" ,
1061
+ ):
1062
+ combine_nested ([da , ds ], concat_dim = "x" )
1054
1063
1055
- def test_combine_coords_mixed_datasets_named_dataarrays (self ):
1064
+ def test_combine_mixed_datasets_named_dataarrays (self ):
1056
1065
da = DataArray (name = "a" , data = [4 , 5 ], dims = "x" , coords = ({"x" : [0 , 1 ]}))
1057
1066
ds = Dataset ({"b" : ("x" , [2 , 3 ])})
1058
- actual = combine_by_coords ([da , ds ])
1059
1067
expected = Dataset (
1060
1068
{"a" : ("x" , [4 , 5 ]), "b" : ("x" , [2 , 3 ])}, coords = {"x" : ("x" , [0 , 1 ])}
1061
1069
)
1070
+
1071
+ actual = combine_by_coords ([da , ds ])
1072
+ assert_identical (expected , actual )
1073
+
1074
+ actual = combine_nested ([da , ds ], concat_dim = "x" )
1062
1075
assert_identical (expected , actual )
1063
1076
1064
- def test_combine_by_coords_all_unnamed_dataarrays (self ):
1077
+ def test_combine_all_unnamed_dataarrays (self ):
1065
1078
unnamed_array = DataArray (data = [1.0 , 2.0 ], coords = {"x" : [0 , 1 ]}, dims = "x" )
1079
+ expected = unnamed_array
1066
1080
1067
1081
actual = combine_by_coords ([unnamed_array ])
1068
- expected = unnamed_array
1082
+ assert_identical (expected , actual )
1083
+
1084
+ actual = combine_nested ([unnamed_array ], concat_dim = None )
1069
1085
assert_identical (expected , actual )
1070
1086
1071
1087
unnamed_array1 = DataArray (data = [1.0 , 2.0 ], coords = {"x" : [0 , 1 ]}, dims = "x" )
1072
1088
unnamed_array2 = DataArray (data = [3.0 , 4.0 ], coords = {"x" : [2 , 3 ]}, dims = "x" )
1073
-
1074
- actual = combine_by_coords ([unnamed_array1 , unnamed_array2 ])
1075
1089
expected = DataArray (
1076
1090
data = [1.0 , 2.0 , 3.0 , 4.0 ], coords = {"x" : [0 , 1 , 2 , 3 ]}, dims = "x"
1077
1091
)
1092
+
1093
+ actual = combine_by_coords ([unnamed_array1 , unnamed_array2 ])
1078
1094
assert_identical (expected , actual )
1079
1095
1080
- def test_combine_by_coords_all_named_dataarrays (self ):
1096
+ actual = combine_nested ([unnamed_array1 , unnamed_array2 ], concat_dim = "x" )
1097
+ assert_identical (expected , actual )
1098
+
1099
+ def test_combine_all_named_dataarrays (self ):
1081
1100
named_da = DataArray (name = "a" , data = [1.0 , 2.0 ], coords = {"x" : [0 , 1 ]}, dims = "x" )
1101
+ expected = named_da .to_dataset ()
1082
1102
1083
1103
actual = combine_by_coords ([named_da ])
1084
- expected = named_da .to_dataset ()
1104
+ assert_identical (expected , actual )
1105
+
1106
+ actual = combine_nested ([named_da ], concat_dim = None )
1085
1107
assert_identical (expected , actual )
1086
1108
1087
1109
named_da1 = DataArray (name = "a" , data = [1.0 , 2.0 ], coords = {"x" : [0 , 1 ]}, dims = "x" )
1088
1110
named_da2 = DataArray (name = "b" , data = [3.0 , 4.0 ], coords = {"x" : [2 , 3 ]}, dims = "x" )
1089
-
1090
- actual = combine_by_coords ([named_da1 , named_da2 ])
1091
1111
expected = Dataset (
1092
1112
{
1093
1113
"a" : DataArray (data = [1.0 , 2.0 ], coords = {"x" : [0 , 1 ]}, dims = "x" ),
1094
1114
"b" : DataArray (data = [3.0 , 4.0 ], coords = {"x" : [2 , 3 ]}, dims = "x" ),
1095
1115
}
1096
1116
)
1117
+
1118
+ actual = combine_by_coords ([named_da1 , named_da2 ])
1119
+ assert_identical (expected , actual )
1120
+
1121
+ actual = combine_nested ([named_da1 , named_da2 ], concat_dim = "x" )
1097
1122
assert_identical (expected , actual )
1098
1123
1099
1124
0 commit comments