5
5
import pytest
6
6
7
7
from xarray import DataArray , Dataset , Variable , concat
8
- from xarray .core import dtypes
9
-
8
+ from xarray .core import dtypes , merge
10
9
from . import (
11
10
InaccessibleArray ,
12
11
assert_array_equal ,
@@ -36,11 +35,15 @@ def test_concat_compat():
36
35
coords = {"x" : [0 , 1 ], "y" : [1 ], "z" : [- 1 , - 2 ], "q" : [0 ]},
37
36
)
38
37
39
- result = concat ([ds1 , ds2 ], dim = "y" , compat = "equals" )
38
+ result = concat ([ds1 , ds2 ], dim = "y" , data_vars = "minimal" , compat = "broadcast_equals" )
39
+ assert_equal (ds2 .no_x_y , result .no_x_y .transpose ())
40
40
41
- for var in ["has_x" , "no_x_y" , "const1" ]:
41
+ for var in ["has_x" , "no_x_y" ]:
42
42
assert "y" not in result [var ]
43
43
44
+ with raises_regex (ValueError , "'q' is not a dimension in all datasets" ):
45
+ concat ([ds1 , ds2 ], dim = "q" , data_vars = "all" , compat = "broadcast_equals" )
46
+
44
47
45
48
class TestConcatDataset :
46
49
@pytest .fixture
@@ -116,7 +119,7 @@ def test_concat_coords(self):
116
119
actual = concat (objs , dim = "x" , coords = coords )
117
120
assert_identical (expected , actual )
118
121
for coords in ["minimal" , []]:
119
- with raises_regex (ValueError , "not equal across " ):
122
+ with raises_regex (merge . MergeError , "conflicting values " ):
120
123
concat (objs , dim = "x" , coords = coords )
121
124
122
125
def test_concat_constant_index (self ):
@@ -127,8 +130,10 @@ def test_concat_constant_index(self):
127
130
for mode in ["different" , "all" , ["foo" ]]:
128
131
actual = concat ([ds1 , ds2 ], "y" , data_vars = mode )
129
132
assert_identical (expected , actual )
130
- with raises_regex (ValueError , "not equal across datasets" ):
131
- concat ([ds1 , ds2 ], "y" , data_vars = "minimal" )
133
+ with raises_regex (merge .MergeError , "conflicting values" ):
134
+ # previously dim="y", and raised error which makes no sense.
135
+ # "foo" has dimension "y" so minimal should concatenate it?
136
+ concat ([ds1 , ds2 ], "new_dim" , data_vars = "minimal" )
132
137
133
138
def test_concat_size0 (self ):
134
139
data = create_test_data ()
@@ -372,10 +377,10 @@ def setUp(self):
372
377
373
378
def test_concat_sensible_compat_errors (self ):
374
379
375
- with raises_regex (ValueError , "'only_x' is not equal across datasets. " ):
380
+ with raises_regex (merge . MergeError , "conflicting values " ):
376
381
concat (self .dsets , data_vars = "sensible" , dim = "y" )
377
382
378
- with raises_regex (ValueError , "'coord1' is not equal across datasets. " ):
383
+ with raises_regex (merge . MergeError , "conflicting values " ):
379
384
concat (self .dsets , coords = "sensible" , dim = "y" )
380
385
381
386
@pytest .mark .parametrize ("concat_dim" , ["y" , "new_dim" ])
@@ -431,7 +436,9 @@ def test_compat_override(self, data_vars, coords):
431
436
432
437
def test_compat_override_different_error (self ):
433
438
with raises_regex (ValueError , "Cannot specify both .*='different'" ):
434
- concat (self .dsets , data_vars = "different" , compat = "override" )
439
+ concat (
440
+ self .dsets , dim = "concat_dim" , data_vars = "different" , compat = "override"
441
+ )
435
442
436
443
437
444
class TestConcatDataArray :
0 commit comments