Skip to content

Commit 91d4d08

Browse files
TomNicholasmax-sixtymathause
authored
Combine='by_coords' and concat dim deprecation in open_mfdataset (#5669)
* deprecate * test * whats-new * Update doc/whats-new.rst Co-authored-by: Mathias Hauser <mathause@users.noreply.github.com> Co-authored-by: Maximilian Roos <5635139+max-sixty@users.noreply.github.com> Co-authored-by: Mathias Hauser <mathause@users.noreply.github.com>
1 parent ebfc6a3 commit 91d4d08

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

doc/whats-new.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ Breaking changes
5656
Deprecations
5757
~~~~~~~~~~~~
5858

59+
- :py:meth:`xarray.open_mfdataset` will now error instead of warn when a value for ``concat_dim`` is
60+
passed alongside ``combine='by_coords'``. By `Tom Nicholas <https://github.com/TomNicholas>`_.
61+
5962

6063
Bug fixes
6164
~~~~~~~~~

xarray/backends/api.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import warnings
32
from glob import glob
43
from io import BytesIO
54
from numbers import Number
@@ -885,15 +884,11 @@ def open_mfdataset(
885884
list(combined_ids_paths.keys()),
886885
list(combined_ids_paths.values()),
887886
)
888-
889-
# TODO raise an error instead of a warning after v0.19
890887
elif combine == "by_coords" and concat_dim is not None:
891-
warnings.warn(
888+
raise ValueError(
892889
"When combine='by_coords', passing a value for `concat_dim` has no "
893-
"effect. This combination will raise an error in future. To manually "
894-
"combine along a specific dimension you should instead specify "
895-
"combine='nested' along with a value for `concat_dim`.",
896-
DeprecationWarning,
890+
"effect. To manually combine along a specific dimension you should "
891+
"instead specify combine='nested' along with a value for `concat_dim`.",
897892
)
898893

899894
open_kwargs = dict(engine=engine, chunks=chunks or {}, **kwargs)

xarray/tests/test_backends.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3497,17 +3497,14 @@ def test_open_mfdataset_auto_combine(self):
34973497
with open_mfdataset([tmp2, tmp1], combine="by_coords") as actual:
34983498
assert_identical(original, actual)
34993499

3500-
# TODO check for an error instead of a warning once deprecated
35013500
def test_open_mfdataset_raise_on_bad_combine_args(self):
35023501
# Regression test for unhelpful error shown in #5230
35033502
original = Dataset({"foo": ("x", np.random.randn(10)), "x": np.arange(10)})
35043503
with create_tmp_file() as tmp1:
35053504
with create_tmp_file() as tmp2:
35063505
original.isel(x=slice(5)).to_netcdf(tmp1)
35073506
original.isel(x=slice(5, 10)).to_netcdf(tmp2)
3508-
with pytest.warns(
3509-
DeprecationWarning, match="`concat_dim` has no effect"
3510-
):
3507+
with pytest.raises(ValueError, match="`concat_dim` has no effect"):
35113508
open_mfdataset([tmp1, tmp2], concat_dim="x")
35123509

35133510
@pytest.mark.xfail(reason="mfdataset loses encoding currently.")

0 commit comments

Comments
 (0)