Repository: pydata/xarray

Issue:
Deprecation cycles to finish for xarray 0.13
Clean-ups we should definitely do:
- [x] remove deprecated options from `xarray.concat` (deprecated back in July 2015!): https://github.com/pydata/xarray/blob/79dc7dc461c7540cc0b84a98543c6f7796c05268/xarray/core/concat.py#L114-L144 (edit by @max-sixty )
- [x] argument order in `DataArray.to_dataset` (also from July 2015) https://github.com/pydata/xarray/blob/41fecd8658ba50ddda0a52e04c21cec5e53415ac/xarray/core/dataarray.py#L491 (edit by @max-sixty )
- [x] remove the warning back reindex with variables with different dimensions (from 2017). This could either be replaced by replacing dimensions like `sel` or by simply raising an error for now and leaving replacing dimensions for later: https://github.com/pydata/xarray/pull/1639): https://github.com/pydata/xarray/blob/79dc7dc461c7540cc0b84a98543c6f7796c05268/xarray/core/alignment.py#L389-L398 (edit by @max-sixty )
- [x] remove `xarray.broadcast_array`, deprecated back in 2016 in https://github.com/pydata/xarray/commit/52ee95f8ae6b9631ac381b5b889de47e41f2440e (edit by @max-sixty )
- [x] remove `Variable.expand_dims` (deprecated back in August 2017), whose implementation actually looks like it's already broken: https://github.com/pydata/xarray/blob/41fecd8658ba50ddda0a52e04c21cec5e53415ac/xarray/core/variable.py#L1232-L1237 (edit by @max-sixty )
- [x] stop supporting a list of colors in the `cmap` argument (dating back to at least v0.7.0): https://github.com/pydata/xarray/blob/d089df385e737f71067309ff7abae15994d581ec/xarray/plot/utils.py#L737-L745 (edit by @max-sixty )
- [x] push the removal of the `compat` and `encoding` arguments from `Dataset`/`DataArray` back to 0.14. These were only deprecated 7 months ago in https://github.com/pydata/xarray/pull/2703. (edit by @max-sixty )

Clean-ups to consider:
- [x] switch the default reduction dimension of groupby and resample? (https://github.com/pydata/xarray/pull/2366) This has been giving a FutureWarning since v0.11.0, released back in November 2018. We could also potentially push this back to 0.14, but these warnings are a little annoying...
- [x] deprecate `auto_combine` (#2616) only since 29 June 2019, so that should be pushed.

Discussion:
shoyer: Can we actually keep the warnings, but just change 0.13 to 0.14?

It's true that `combine_nested` and `combine_by_coords` only solve *most* of the use cases for `auto_combine`, but I'm still not sure it's worth keeping around the later.

Patch:
diff --git a/doc/whats-new.rst b/doc/whats-new.rst
index 567e7405..57da2910 100644
--- a/doc/whats-new.rst
+++ b/doc/whats-new.rst
@@ -54,6 +54,9 @@ Breaking changes
     error in a later release.
 
   (:issue:`3250`) by `Guido Imperiale <https://github.com/crusaderky>`_.
+- The default dimension for :py:meth:`~xarray.Dataset.groupby`, :py:meth:`~xarray.Dataset.resample`,
+  :py:meth:`~xarray.DataArray.groupby` and :py:meth:`~xarray.DataArray.resample` reductions is now the
+  grouping or resampling dimension.
 - :py:meth:`~Dataset.to_dataset` requires ``name`` to be passed as a kwarg (previously ambiguous
   positional arguments were deprecated)
 - Reindexing with variables of a different dimension now raise an error (previously deprecated)
diff --git a/xarray/backends/api.py b/xarray/backends/api.py
index 1f0869cf..0d6dedac 100644
--- a/xarray/backends/api.py
+++ b/xarray/backends/api.py
@@ -915,7 +915,7 @@ def open_mfdataset(
             # Remove this after deprecation cycle from #2616 is complete
             basic_msg = dedent(
                 """\
-            In xarray version 0.13 the default behaviour of `open_mfdataset`
+            In xarray version 0.14 the default behaviour of `open_mfdataset`
             will change. To retain the existing behavior, pass
             combine='nested'. To use future default behavior, pass
             combine='by_coords'. See
diff --git a/xarray/core/combine.py b/xarray/core/combine.py
index e35bb51e..be7fd865 100644
--- a/xarray/core/combine.py
+++ b/xarray/core/combine.py
@@ -716,7 +716,7 @@ def auto_combine(
     if not from_openmfds:
         basic_msg = dedent(
             """\
-        In xarray version 0.13 `auto_combine` will be deprecated. See
+        In xarray version 0.14 `auto_combine` will be deprecated. See
         http://xarray.pydata.org/en/stable/combining.html#combining-multi"""
         )
         warnings.warn(basic_msg, FutureWarning, stacklevel=2)
@@ -758,7 +758,7 @@ def auto_combine(
         message += dedent(
             """\
         The datasets supplied require both concatenation and merging. From
-        xarray version 0.13 this will operation will require either using the
+        xarray version 0.14 this will operation will require either using the
         new `combine_nested` function (or the `combine='nested'` option to
         open_mfdataset), with a nested list structure such that you can combine
         along the dimensions {}. Alternatively if your datasets have global
diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py
index 8a53e7ba..693e94e2 100644
--- a/xarray/core/dataset.py
+++ b/xarray/core/dataset.py
@@ -3875,9 +3875,7 @@ class Dataset(Mapping, ImplementsDatasetReduce, DataWithCoords):
             Dataset with this object's DataArrays replaced with new DataArrays
             of summarized data and the indicated dimension(s) removed.
         """
-        if dim is ALL_DIMS:
-            dim = None
-        if dim is None:
+        if dim is None or dim is ALL_DIMS:
             dims = set(self.dims)
         elif isinstance(dim, str) or not isinstance(dim, Iterable):
             dims = {dim}
@@ -4803,7 +4801,7 @@ class Dataset(Mapping, ImplementsDatasetReduce, DataWithCoords):
 
         if isinstance(dim, str):
             dims = {dim}
-        elif dim is None:
+        elif dim is None or dim is ALL_DIMS:
             dims = set(self.dims)
         else:
             dims = set(dim)
diff --git a/xarray/core/groupby.py b/xarray/core/groupby.py
index 41de4846..bae3057a 100644
--- a/xarray/core/groupby.py
+++ b/xarray/core/groupby.py
@@ -5,9 +5,9 @@ import warnings
 import numpy as np
 import pandas as pd
 
-from . import dtypes, duck_array_ops, nputils, ops, utils
+from . import dtypes, duck_array_ops, nputils, ops
 from .arithmetic import SupportsArithmetic
-from .common import ALL_DIMS, ImplementsArrayReduce, ImplementsDatasetReduce
+from .common import ImplementsArrayReduce, ImplementsDatasetReduce
 from .concat import concat
 from .options import _get_keep_attrs
 from .pycompat import integer_types
@@ -700,19 +700,8 @@ class DataArrayGroupBy(GroupBy, ImplementsArrayReduce):
         numpy.nanpercentile, pandas.Series.quantile, Dataset.quantile,
         DataArray.quantile
         """
-        if dim == DEFAULT_DIMS:
-            dim = ALL_DIMS
-            # TODO change this to dim = self._group_dim after
-            # the deprecation process
-            if self._obj.ndim > 1:
-                warnings.warn(
-                    "Default reduction dimension will be changed to the "
-                    "grouped dimension in a future version of xarray. To "
-                    "silence this warning, pass dim=xarray.ALL_DIMS "
-                    "explicitly.",
-                    FutureWarning,
-                    stacklevel=2,
-                )
+        if dim is None:
+            dim = self._group_dim
 
         out = self.apply(
             self._obj.__class__.quantile,
@@ -758,20 +747,6 @@ class DataArrayGroupBy(GroupBy, ImplementsArrayReduce):
             Array with summarized data and the indicated dimension(s)
             removed.
         """
-        if dim == DEFAULT_DIMS:
-            dim = ALL_DIMS
-            # TODO change this to dim = self._group_dim after
-            # the deprecation process
-            if self._obj.ndim > 1:
-                warnings.warn(
-                    "Default reduction dimension will be changed to the "
-                    "grouped dimension in a future version of xarray. To "
-                    "silence this warning, pass dim=xarray.ALL_DIMS "
-                    "explicitly.",
-                    FutureWarning,
-                    stacklevel=2,
-                )
-
         if keep_attrs is None:
             keep_attrs = _get_keep_attrs(default=False)
 
@@ -780,43 +755,6 @@ class DataArrayGroupBy(GroupBy, ImplementsArrayReduce):
 
         return self.apply(reduce_array, shortcut=shortcut)
 
-    # TODO remove the following class method and DEFAULT_DIMS after the
-    # deprecation cycle
-    @classmethod
-    def _reduce_method(cls, func, include_skipna, numeric_only):
-        if include_skipna:
-
-            def wrapped_func(
-                self,
-                dim=DEFAULT_DIMS,
-                axis=None,
-                skipna=None,
-                keep_attrs=None,
-                **kwargs
-            ):
-                return self.reduce(
-                    func,
-                    dim,
-                    axis,
-                    keep_attrs=keep_attrs,
-                    skipna=skipna,
-                    allow_lazy=True,
-                    **kwargs
-                )
-
-        else:
-
-            def wrapped_func(  # type: ignore
-                self, dim=DEFAULT_DIMS, axis=None, keep_attrs=None, **kwargs
-            ):
-                return self.reduce(
-                    func, dim, axis, keep_attrs=keep_attrs, allow_lazy=True, **kwargs
-                )
-
-        return wrapped_func
-
-
-DEFAULT_DIMS = utils.ReprObject("<default-dims>")
 
 ops.inject_reduce_methods(DataArrayGroupBy)
 ops.inject_binary_ops(DataArrayGroupBy)
@@ -898,19 +836,7 @@ class DatasetGroupBy(GroupBy, ImplementsDatasetReduce):
             Array with summarized data and the indicated dimension(s)
             removed.
         """
-        if dim == DEFAULT_DIMS:
-            dim = ALL_DIMS
-            # TODO change this to dim = self._group_dim after
-            # the deprecation process. Do not forget to remove _reduce_method
-            warnings.warn(
-                "Default reduction dimension will be changed to the "
-                "grouped dimension in a future version of xarray. To "
-                "silence this warning, pass dim=xarray.ALL_DIMS "
-                "explicitly.",
-                FutureWarning,
-                stacklevel=2,
-            )
-        elif dim is None:
+        if dim is None:
             dim = self._group_dim
 
         if keep_attrs is None:
@@ -921,31 +847,6 @@ class DatasetGroupBy(GroupBy, ImplementsDatasetReduce):
 
         return self.apply(reduce_dataset)
 
-    # TODO remove the following class method and DEFAULT_DIMS after the
-    # deprecation cycle
-    @classmethod
-    def _reduce_method(cls, func, include_skipna, numeric_only):
-        if include_skipna:
-
-            def wrapped_func(self, dim=DEFAULT_DIMS, skipna=None, **kwargs):
-                return self.reduce(
-                    func,
-                    dim,
-                    skipna=skipna,
-                    numeric_only=numeric_only,
-                    allow_lazy=True,
-                    **kwargs
-                )
-
-        else:
-
-            def wrapped_func(self, dim=DEFAULT_DIMS, **kwargs):  # type: ignore
-                return self.reduce(
-                    func, dim, numeric_only=numeric_only, allow_lazy=True, **kwargs
-                )
-
-        return wrapped_func
-
     def assign(self, **kwargs):
         """Assign data variables by group.
 
diff --git a/xarray/core/resample.py b/xarray/core/resample.py
index de70ebb6..1f2e5c0b 100644
--- a/xarray/core/resample.py
+++ b/xarray/core/resample.py
@@ -1,5 +1,5 @@
 from . import ops
-from .groupby import DEFAULT_DIMS, DataArrayGroupBy, DatasetGroupBy
+from .groupby import DataArrayGroupBy, DatasetGroupBy
 
 RESAMPLE_DIM = "__resample_dim__"
 
@@ -307,9 +307,6 @@ class DatasetResample(DatasetGroupBy, Resample):
             Array with summarized data and the indicated dimension(s)
             removed.
         """
-        if dim == DEFAULT_DIMS:
-            dim = None
-
         return super().reduce(func, dim, keep_attrs, **kwargs)
 
 


Test patch:
diff --git a/xarray/tests/test_combine.py b/xarray/tests/test_combine.py
index 1abca30d..6037669a 100644
--- a/xarray/tests/test_combine.py
+++ b/xarray/tests/test_combine.py
@@ -714,7 +714,7 @@ class TestCombineAuto:
 
 
 @pytest.mark.filterwarnings(
-    "ignore:In xarray version 0.13 `auto_combine` " "will be deprecated"
+    "ignore:In xarray version 0.14 `auto_combine` " "will be deprecated"
 )
 @pytest.mark.filterwarnings("ignore:Also `open_mfdataset` will no longer")
 @pytest.mark.filterwarnings("ignore:The datasets supplied")
diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py
index 49980c75..01e92bdd 100644
--- a/xarray/tests/test_dataarray.py
+++ b/xarray/tests/test_dataarray.py
@@ -2499,16 +2499,6 @@ class TestDataArray:
         assert_allclose(expected_sum_axis1, grouped.reduce(np.sum, "y"))
         assert_allclose(expected_sum_axis1, grouped.sum("y"))
 
-    def test_groupby_warning(self):
-        array = self.make_groupby_example_array()
-        grouped = array.groupby("y")
-        with pytest.warns(FutureWarning):
-            grouped.sum()
-
-    @pytest.mark.skipif(
-        LooseVersion(xr.__version__) < LooseVersion("0.13"),
-        reason="not to forget the behavior change",
-    )
     def test_groupby_sum_default(self):
         array = self.make_groupby_example_array()
         grouped = array.groupby("abc")
@@ -2529,7 +2519,7 @@ class TestDataArray:
             }
         )["foo"]
 
-        assert_allclose(expected_sum_all, grouped.sum())
+        assert_allclose(expected_sum_all, grouped.sum(dim="y"))
 
     def test_groupby_count(self):
         array = DataArray(
diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py
index d8401e0b..7d2b11d0 100644
--- a/xarray/tests/test_dataset.py
+++ b/xarray/tests/test_dataset.py
@@ -3367,18 +3367,6 @@ class TestDataset:
         actual = data.groupby("letters").mean(ALL_DIMS)
         assert_allclose(expected, actual)
 
-    def test_groupby_warn(self):
-        data = Dataset(
-            {
-                "xy": (["x", "y"], np.random.randn(3, 4)),
-                "xonly": ("x", np.random.randn(3)),
-                "yonly": ("y", np.random.randn(4)),
-                "letters": ("y", ["a", "a", "b", "b"]),
-            }
-        )
-        with pytest.warns(FutureWarning):
-            data.groupby("x").mean()
-
     def test_groupby_math(self):
         def reorder_dims(x):
             return x.transpose("dim1", "dim2", "dim3", "time")
diff --git a/xarray/tests/test_groupby.py b/xarray/tests/test_groupby.py
index 9127eb71..ee17cc39 100644
--- a/xarray/tests/test_groupby.py
+++ b/xarray/tests/test_groupby.py
@@ -134,21 +134,21 @@ def test_da_groupby_quantile():
         [("x", [1, 1, 1, 2, 2]), ("y", [0, 0, 1])],
     )
 
-    actual_x = array.groupby("x").quantile(0)
+    actual_x = array.groupby("x").quantile(0, dim=xr.ALL_DIMS)
     expected_x = xr.DataArray([1, 4], [("x", [1, 2])])
     assert_identical(expected_x, actual_x)
 
-    actual_y = array.groupby("y").quantile(0)
+    actual_y = array.groupby("y").quantile(0, dim=xr.ALL_DIMS)
     expected_y = xr.DataArray([1, 22], [("y", [0, 1])])
     assert_identical(expected_y, actual_y)
 
-    actual_xx = array.groupby("x").quantile(0, dim="x")
+    actual_xx = array.groupby("x").quantile(0)
     expected_xx = xr.DataArray(
         [[1, 11, 22], [4, 15, 24]], [("x", [1, 2]), ("y", [0, 0, 1])]
     )
     assert_identical(expected_xx, actual_xx)
 
-    actual_yy = array.groupby("y").quantile(0, dim="y")
+    actual_yy = array.groupby("y").quantile(0)
     expected_yy = xr.DataArray(
         [[1, 26], [2, 22], [3, 23], [4, 24], [5, 25]],
         [("x", [1, 1, 1, 2, 2]), ("y", [0, 1])],
@@ -164,7 +164,7 @@ def test_da_groupby_quantile():
     )
     g = foo.groupby(foo.time.dt.month)
 
-    actual = g.quantile(0)
+    actual = g.quantile(0, dim=xr.ALL_DIMS)
     expected = xr.DataArray(
         [
             0.0,