From 23cc7f43c7f454d07c5a820a2639a51c2b02a4ad Mon Sep 17 00:00:00 2001 From: dcherian Date: Tue, 12 Nov 2019 07:48:32 -0700 Subject: [PATCH 1/3] warn if dim is passed to rolling operations. --- doc/whats-new.rst | 3 +++ xarray/core/rolling.py | 9 +++++++++ xarray/tests/test_dataarray.py | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 96f0ba9a4a6..143e5a7f45f 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -217,6 +217,9 @@ Bug fixes By `Deepak Cherian `_. - Fix error in concatenating unlabeled dimensions (:pull:`3362`). By `Deepak Cherian `_. +- Warn if the ``dim`` kwarg is passed to rolling operations. This is redundant since a dimension is + specified when the :py:class:``DatasetRolling`` or :py:class:``DataArrayRolling`` object is created. + (:pull:`3362`). By `Deepak Cherian `_. Documentation ~~~~~~~~~~~~~ diff --git a/xarray/core/rolling.py b/xarray/core/rolling.py index f4e571a8efe..9063a312234 100644 --- a/xarray/core/rolling.py +++ b/xarray/core/rolling.py @@ -1,4 +1,5 @@ import functools +import warnings from typing import Callable import numpy as np @@ -351,6 +352,14 @@ def _bottleneck_reduce(self, func, **kwargs): def _numpy_or_bottleneck_reduce( self, array_agg_func, bottleneck_move_func, **kwargs ): + if "dim" in kwargs: + warnings.warn( + f"Reductions will be applied along the rolling dimension '{self.dim}'. Passing the 'dim' kwarg passed to reduction operations is deprecated and will be removed in xarray 0.16.0.", + DeprecationWarning, + stacklevel=3, + ) + del kwargs["dim"] + if bottleneck_move_func is not None and not isinstance( self.obj.data, dask_array_type ): diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index 42fae2c9dd4..7c6dc1825a1 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -4188,6 +4188,9 @@ def test_rolling_wrapped_bottleneck(da, name, center, min_periods): ) assert_array_equal(actual.values, expected) + with pytest.warns(DeprecationWarning, match="Reductions will be applied"): + getattr(rolling_obj, name)(dim="time") + # Test center rolling_obj = da.rolling(time=7, center=center) actual = getattr(rolling_obj, name)()["time"] @@ -4203,6 +4206,9 @@ def test_rolling_wrapped_dask(da_dask, name, center, min_periods, window): # dask version rolling_obj = da_dask.rolling(time=window, min_periods=min_periods, center=center) actual = getattr(rolling_obj, name)().load() + if name != "count": + with pytest.warns(DeprecationWarning, match="Reductions will be applied"): + getattr(rolling_obj, name)(dim="time") # numpy version rolling_obj = da_dask.load().rolling( time=window, min_periods=min_periods, center=center From 51ab976f2c5dd784d0937a2de5835a4e7edcdb1a Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Tue, 12 Nov 2019 19:01:38 +0000 Subject: [PATCH 2/3] Update doc/whats-new.rst Co-Authored-By: Maximilian Roos <5635139+max-sixty@users.noreply.github.com> --- doc/whats-new.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 143e5a7f45f..f53b8c9bb75 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -218,7 +218,7 @@ Bug fixes - Fix error in concatenating unlabeled dimensions (:pull:`3362`). By `Deepak Cherian `_. - Warn if the ``dim`` kwarg is passed to rolling operations. This is redundant since a dimension is - specified when the :py:class:``DatasetRolling`` or :py:class:``DataArrayRolling`` object is created. + specified when the :py:class:`DatasetRolling` or :py:class:`DataArrayRolling` object is created. (:pull:`3362`). By `Deepak Cherian `_. Documentation From 855de1043323eea78b36da6b14e8f1fde88c73b3 Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Tue, 12 Nov 2019 19:02:00 +0000 Subject: [PATCH 3/3] Update xarray/core/rolling.py Co-Authored-By: Maximilian Roos <5635139+max-sixty@users.noreply.github.com> --- xarray/core/rolling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/core/rolling.py b/xarray/core/rolling.py index 9063a312234..a1864332f4d 100644 --- a/xarray/core/rolling.py +++ b/xarray/core/rolling.py @@ -354,7 +354,7 @@ def _numpy_or_bottleneck_reduce( ): if "dim" in kwargs: warnings.warn( - f"Reductions will be applied along the rolling dimension '{self.dim}'. Passing the 'dim' kwarg passed to reduction operations is deprecated and will be removed in xarray 0.16.0.", + f"Reductions will be applied along the rolling dimension '{self.dim}'. Passing the 'dim' kwarg to reduction operations has no effect and will raise an error in xarray 0.16.0.", DeprecationWarning, stacklevel=3, )