Skip to content

Commit

Permalink
removed mention that 'dims' are inferred from 'coords'-dict when omit… (
Browse files Browse the repository at this point in the history
pydata#3821)

* removed mention that 'dims' are inferred from 'coords'-dict when omitted in DataArray (fixes pydata#3820)

* added summary of PR pydata#3821 to whats-new
  • Loading branch information
sjvrijn authored and max-sixty committed Mar 4, 2020
1 parent 1c5e1cd commit 88690fd
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 29 deletions.
3 changes: 3 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ Bug fixes

Documentation
~~~~~~~~~~~~~
- Fix documentation of :py:class:`DataArray` removing the deprecated mention
that when omitted, `dims` are inferred from a `coords`-dict. (:pull:`3821`)
By `Sander van Rijn <https://github.com/sjvrijn>`_.

Internal Changes
~~~~~~~~~~~~~~~~
Expand Down
17 changes: 3 additions & 14 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime
import functools
import warnings
from numbers import Number
from typing import (
TYPE_CHECKING,
Expand Down Expand Up @@ -304,8 +303,7 @@ def __init__(
Name(s) of the data dimension(s). Must be either a hashable (only
for 1D data) or a sequence of hashables with length equal to the
number of dimensions. If this argument is omitted, dimension names
are taken from ``coords`` (if possible) and otherwise default to
``['dim_0', ... 'dim_n']``.
default to ``['dim_0', ... 'dim_n']``.
name : str or None, optional
Name of this array.
attrs : dict_like or None, optional
Expand Down Expand Up @@ -1860,15 +1858,15 @@ 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
----------
*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
Expand Down Expand Up @@ -1897,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
Expand Down
10 changes: 1 addition & 9 deletions xarray/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions xarray/tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 88690fd

Please sign in to comment.