Skip to content

Commit b683b37

Browse files
committed
Clean up combine
1 parent 0b99b85 commit b683b37

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

xarray/tests/test_combine.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,10 @@ def test_get_new_tile_ids(self, create_combined_ids):
280280

281281

282282
class TestCombineND:
283-
@pytest.mark.parametrize("concat_dim", ["dim1", "new_dim"])
284-
def test_concat_once(self, create_combined_ids, concat_dim):
283+
@pytest.mark.parametrize(
284+
"concat_dim, kwargs", [("dim1", {}), ("new_dim", {"data_vars": "all"})]
285+
)
286+
def test_concat_once(self, create_combined_ids, concat_dim, kwargs):
285287
shape = (2,)
286288
combined_ids = create_combined_ids(shape)
287289
ds = create_test_data
@@ -296,7 +298,7 @@ def test_concat_once(self, create_combined_ids, concat_dim):
296298
combine_attrs="drop",
297299
)
298300

299-
expected_ds = concat([ds(0), ds(1)], data_vars="all", dim=concat_dim)
301+
expected_ds = concat([ds(0), ds(1)], dim=concat_dim, **kwargs)
300302
assert_combined_tile_ids_equal(result, {(): expected_ds})
301303

302304
def test_concat_only_first_dim(self, create_combined_ids):
@@ -322,8 +324,10 @@ def test_concat_only_first_dim(self, create_combined_ids):
322324

323325
assert_combined_tile_ids_equal(result, expected)
324326

325-
@pytest.mark.parametrize("concat_dim", ["dim1", "new_dim"])
326-
def test_concat_twice(self, create_combined_ids, concat_dim):
327+
@pytest.mark.parametrize(
328+
"concat_dim, kwargs", [("dim1", {}), ("new_dim", {"data_vars": "all"})]
329+
)
330+
def test_concat_twice(self, create_combined_ids, concat_dim, kwargs):
327331
shape = (2, 3)
328332
combined_ids = create_combined_ids(shape)
329333
result = _combine_nd(
@@ -341,9 +345,7 @@ def test_concat_twice(self, create_combined_ids, concat_dim):
341345
partway1 = concat([ds(0), ds(3)], dim="dim1")
342346
partway2 = concat([ds(1), ds(4)], dim="dim1")
343347
partway3 = concat([ds(2), ds(5)], dim="dim1")
344-
expected = concat(
345-
[partway1, partway2, partway3], data_vars="all", dim=concat_dim
346-
)
348+
expected = concat([partway1, partway2, partway3], **kwargs, dim=concat_dim)
347349

348350
assert_equal(result, expected)
349351

@@ -448,15 +450,19 @@ def test_nested_concat_along_new_dim(self):
448450

449451
def test_nested_merge_with_self(self):
450452
data = Dataset({"x": 0})
451-
actual = combine_nested(
452-
[data, data, data], compat="no_conflicts", concat_dim=None
453-
)
453+
actual = combine_nested([data, data, data], concat_dim=None)
454454
assert_identical(data, actual)
455455

456456
def test_nested_merge_with_overlapping_values(self):
457457
ds1 = Dataset({"a": ("x", [1, 2]), "x": [0, 1]})
458458
ds2 = Dataset({"a": ("x", [2, 3]), "x": [1, 2]})
459459
expected = Dataset({"a": ("x", [1, 2, 3]), "x": [0, 1, 2]})
460+
with pytest.warns(
461+
FutureWarning,
462+
match="will change from compat='no_conflicts' to compat='override'",
463+
):
464+
actual = combine_nested([ds1, ds2], join="outer", concat_dim=None)
465+
assert_identical(expected, actual)
460466
actual = combine_nested(
461467
[ds1, ds2], join="outer", compat="no_conflicts", concat_dim=None
462468
)
@@ -466,11 +472,16 @@ def test_nested_merge_with_overlapping_values(self):
466472
)
467473
assert_identical(expected, actual)
468474

469-
def test_nested_merge_with_nan(self):
475+
def test_nested_merge_with_nan_no_conflicts(self):
470476
tmp1 = Dataset({"x": 0})
471477
tmp2 = Dataset({"x": np.nan})
472478
actual = combine_nested([tmp1, tmp2], compat="no_conflicts", concat_dim=None)
473479
assert_identical(tmp1, actual)
480+
with pytest.warns(
481+
FutureWarning,
482+
match="will change from compat='no_conflicts' to compat='override'",
483+
):
484+
combine_nested([tmp1, tmp2], concat_dim=None)
474485
actual = combine_nested([tmp1, tmp2], compat="no_conflicts", concat_dim=[None])
475486
assert_identical(tmp1, actual)
476487

@@ -543,7 +554,6 @@ def test_auto_combine_2d(self):
543554
result = combine_nested(
544555
datasets,
545556
data_vars="all",
546-
compat="no_conflicts",
547557
concat_dim=["dim1", "dim2"],
548558
)
549559
assert_equal(result, expected)
@@ -588,7 +598,6 @@ def test_auto_combine_2d_combine_attrs_kwarg(self):
588598
datasets,
589599
concat_dim=["dim1", "dim2"],
590600
data_vars="all",
591-
compat="no_conflicts",
592601
combine_attrs="identical",
593602
)
594603

@@ -597,7 +606,6 @@ def test_auto_combine_2d_combine_attrs_kwarg(self):
597606
datasets,
598607
concat_dim=["dim1", "dim2"],
599608
data_vars="all",
600-
compat="no_conflicts",
601609
combine_attrs=combine_attrs,
602610
)
603611
assert_identical(result, expected)
@@ -995,9 +1003,7 @@ def test_combine_by_coords_combine_attrs_variables(
9951003
with pytest.raises(MergeError, match="combine_attrs"):
9961004
combine_by_coords([data1, data2], combine_attrs=combine_attrs)
9971005
else:
998-
actual = combine_by_coords(
999-
[data1, data2], data_vars="all", combine_attrs=combine_attrs
1000-
)
1006+
actual = combine_by_coords([data1, data2], combine_attrs=combine_attrs)
10011007
expected = Dataset(
10021008
{
10031009
"x": ("a", [0, 1], expected_attrs),
@@ -1011,7 +1017,7 @@ def test_combine_by_coords_combine_attrs_variables(
10111017
def test_infer_order_from_coords(self):
10121018
data = create_test_data()
10131019
objs = [data.isel(dim2=slice(4, 9)), data.isel(dim2=slice(4))]
1014-
actual = combine_by_coords(objs, data_vars="all", compat="no_conflicts")
1020+
actual = combine_by_coords(objs, data_vars="all")
10151021
expected = data
10161022
assert expected.broadcast_equals(actual)
10171023

@@ -1178,9 +1184,7 @@ def test_combine_by_coords_all_dataarrays_with_the_same_name(self):
11781184
named_da1 = DataArray(name="a", data=[1.0, 2.0], coords={"x": [0, 1]}, dims="x")
11791185
named_da2 = DataArray(name="a", data=[3.0, 4.0], coords={"x": [2, 3]}, dims="x")
11801186

1181-
actual = combine_by_coords(
1182-
[named_da1, named_da2], compat="no_conflicts", join="outer"
1183-
)
1187+
actual = combine_by_coords([named_da1, named_da2], join="outer")
11841188
expected = merge([named_da1, named_da2], compat="no_conflicts", join="outer")
11851189
assert_identical(expected, actual)
11861190

0 commit comments

Comments
 (0)