From 107a9b434a5b51b62ed9ba6ef4a88c4f55890587 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Tue, 3 Mar 2020 20:43:59 -0500 Subject: [PATCH 1/4] transpose coords by default --- xarray/core/dataarray.py | 14 ++------------ xarray/core/groupby.py | 10 +--------- xarray/tests/test_dataarray.py | 6 ------ 3 files changed, 3 insertions(+), 27 deletions(-) diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index b1da0ca1448..2f023d0c25c 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -1,6 +1,5 @@ import datetime import functools -import warnings from numbers import Number from typing import ( TYPE_CHECKING, @@ -1859,7 +1858,7 @@ def to_unstacked_dataset(self, dim, level=0): # unstacked dataset return Dataset(data_dict) - def transpose(self, *dims: Hashable, transpose_coords: bool = None) -> "DataArray": + def transpose(self, *dims: Hashable, transpose_coords: bool = True) -> "DataArray": """Return a new DataArray object with transposed dimensions. Parameters @@ -1867,7 +1866,7 @@ def transpose(self, *dims: Hashable, transpose_coords: bool = None) -> "DataArra *dims : hashable, optional By default, reverse the dimensions. Otherwise, reorder the dimensions to this order. - transpose_coords : boolean, optional + transpose_coords : boolean, default True If True, also transpose the coordinates of this DataArray. Returns @@ -1896,15 +1895,6 @@ def transpose(self, *dims: Hashable, transpose_coords: bool = None) -> "DataArra coords[name] = coord.variable.transpose(*coord_dims) return self._replace(variable, coords) else: - if transpose_coords is None and any(self[c].ndim > 1 for c in self.coords): - warnings.warn( - "This DataArray contains multi-dimensional " - "coordinates. In the future, these coordinates " - "will be transposed as well unless you specify " - "transpose_coords=False.", - FutureWarning, - stacklevel=2, - ) return self._replace(variable) @property diff --git a/xarray/core/groupby.py b/xarray/core/groupby.py index f2a9ebac6eb..3c78882d5b8 100644 --- a/xarray/core/groupby.py +++ b/xarray/core/groupby.py @@ -292,7 +292,7 @@ def __init__( bins : array-like, optional If `bins` is specified, the groups will be discretized into the specified bins by `pandas.cut`. - restore_coord_dims : bool, optional + restore_coord_dims : bool, default True If True, also restore the dimension order of multi-dimensional coordinates. cut_kwargs : dict, optional @@ -390,14 +390,6 @@ def __init__( and restore_coord_dims is None and any(obj[c].ndim > 1 for c in obj.coords) ): - warnings.warn( - "This DataArray contains multi-dimensional " - "coordinates. In the future, the dimension order " - "of these coordinates will be restored as well " - "unless you specify restore_coord_dims=False.", - FutureWarning, - stacklevel=2, - ) restore_coord_dims = False # specification for the groupby operation diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index 0a622d279ba..3e5d8361bd1 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -2119,9 +2119,6 @@ def test_transpose(self): with pytest.raises(ValueError): da.transpose("x", "y") - with pytest.warns(FutureWarning): - da.transpose() - def test_squeeze(self): assert_equal(self.dv.variable.squeeze(), self.dv.squeeze().variable) @@ -2703,9 +2700,6 @@ def test_groupby_restore_coord_dims(self): )["c"] assert result.dims == expected_dims - with pytest.warns(FutureWarning): - array.groupby("x").map(lambda x: x.squeeze()) - def test_groupby_first_and_last(self): array = DataArray([1, 2, 3, 4, 5], dims="x") by = DataArray(["a"] * 2 + ["b"] * 3, dims="x", name="ab") From e7a423f4aa98494144419feaa587ea8190751a56 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Mon, 23 Mar 2020 21:07:00 -0400 Subject: [PATCH 2/4] whatsnew --- doc/whats-new.rst | 3 +++ xarray/core/groupby.py | 9 +-------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 10f6b23ca66..a3565dd4fb2 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -21,6 +21,9 @@ v0.16.0 (unreleased) Breaking changes ~~~~~~~~~~~~~~~~ +- ``groupby`` operations will restore coord dimension order. Pass ``restore_coord_dims=False`` + to maintain existing behavior. + By `Maximilian Roos `_ New Features ~~~~~~~~~~~~ diff --git a/xarray/core/groupby.py b/xarray/core/groupby.py index d93ed578f7b..126ce0e7dd8 100644 --- a/xarray/core/groupby.py +++ b/xarray/core/groupby.py @@ -272,7 +272,7 @@ def __init__( squeeze=False, grouper=None, bins=None, - restore_coord_dims=None, + restore_coord_dims=True, cut_kwargs={}, ): """Create a GroupBy object @@ -385,13 +385,6 @@ def __init__( "Failed to group data. Are you grouping by a variable that is all NaN?" ) - if ( - isinstance(obj, DataArray) - and restore_coord_dims is None - and any(obj[c].ndim > 1 for c in obj.coords) - ): - restore_coord_dims = False - # specification for the groupby operation self._obj = obj self._group = group From 938db8b5e98acd125aede163395073fa8bcd8916 Mon Sep 17 00:00:00 2001 From: Maximilian Roos <5635139+max-sixty@users.noreply.github.com> Date: Wed, 6 May 2020 12:36:18 -0400 Subject: [PATCH 3/4] Update doc/whats-new.rst Co-authored-by: crusaderky --- doc/whats-new.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index b02917e62aa..ebb9a2d3da2 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -23,7 +23,9 @@ Breaking changes ~~~~~~~~~~~~~~~~ - ``groupby`` operations will restore coord dimension order. Pass ``restore_coord_dims=False`` - to maintain existing behavior. + to revert to previous behavior. + :meth:`DataArray.transpose` will now transpose coordinates by default. + Pass ``transpose_coords=False`` to revert to previous behaviour. By `Maximilian Roos `_ - Alternate draw styles for :py:meth:`plot.step` must be passed using the ``drawstyle`` (or ``ds``) keyword argument, instead of the ``linestyle`` (or From e7c42300f2f713a590a48e70bd41358eb0055f45 Mon Sep 17 00:00:00 2001 From: Maximilian Roos <5635139+max-sixty@users.noreply.github.com> Date: Wed, 6 May 2020 09:38:31 -0700 Subject: [PATCH 4/4] Update whats-new.rst --- 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 ebb9a2d3da2..1204155f062 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -24,7 +24,7 @@ Breaking changes - ``groupby`` operations will restore coord dimension order. Pass ``restore_coord_dims=False`` to revert to previous behavior. - :meth:`DataArray.transpose` will now transpose coordinates by default. +- :meth:`DataArray.transpose` will now transpose coordinates by default. Pass ``transpose_coords=False`` to revert to previous behaviour. By `Maximilian Roos `_ - Alternate draw styles for :py:meth:`plot.step` must be passed using the