diff --git a/ci/requirements/py36-min-nep18.yml b/ci/requirements/py36-min-nep18.yml index 17aae6932ac..14982c1d5e7 100644 --- a/ci/requirements/py36-min-nep18.yml +++ b/ci/requirements/py36-min-nep18.yml @@ -10,7 +10,7 @@ dependencies: - distributed=2.9 - numpy=1.17 - pandas=0.25 - - pint=0.13 + - pint=0.15 - pip - pytest - pytest-cov diff --git a/doc/whats-new.rst b/doc/whats-new.rst index f624e89019d..4b451fcbc18 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -33,7 +33,7 @@ New Features now accept more than 1 dimension. (:pull:`4219`) By `Keisuke Fujii `_. - ``min_count`` can be supplied to reductions such as ``.sum`` when specifying - multiple dimension to reduce over. (:pull:`4356`) + multiple dimension to reduce over. (:pull:`4356`) By `Maximilian Roos `_. - :py:func:`xarray.cov` and :py:func:`xarray.corr` now handle missing values. (:pull:`4351`) By `Maximilian Roos `_. @@ -77,7 +77,7 @@ Bug fixes and :py:meth:`DataArray.str.wrap` (:issue:`4334`). By `Mathias Hauser `_. - Fixed overflow issue causing incorrect results in computing means of :py:class:`cftime.datetime` arrays (:issue:`4341`). By `Spencer Clark `_. -- Fixed :py:meth:`Dataset.coarsen`, :py:meth:`DataArray.coarsen` dropping attributes on original object (:issue:`4120`, :pull:`4360`). by `Julia Kent `_. +- Fixed :py:meth:`Dataset.coarsen`, :py:meth:`DataArray.coarsen` dropping attributes on original object (:issue:`4120`, :pull:`4360`). By `Julia Kent `_. - fix the signature of the plot methods. (:pull:`4359`) By `Justus Magin `_. - Fix :py:func:`xarray.apply_ufunc` with ``vectorize=True`` and ``exclude_dims`` (:issue:`3890`). By `Mathias Hauser `_. @@ -86,6 +86,8 @@ Bug fixes By `Jens Svensmark `_ - Fix incorrect legend labels for :py:meth:`Dataset.plot.scatter` (:issue:`4126`). By `Peter Hausamann `_. +- Avoid relying on :py:class:`set` objects for the ordering of the coordinates (:pull:`4409`) + By `Justus Magin `_. - Fix indexing with datetime64 scalars with pandas 1.1 (:issue:`4283`). By `Stephan Hoyer `_ and `Justus Magin `_. @@ -99,6 +101,8 @@ Documentation By `Sander van Rijn `_ - Update the contributing guide to use merges instead of rebasing and state that we squash-merge. (:pull:`4355`) By `Justus Magin `_. +- Make sure the examples from the docstrings actually work (:pull:`4408`). + By `Justus Magin `_. - Updated Vectorized Indexing to a clearer example. By `Maximilian Roos `_ diff --git a/xarray/core/concat.py b/xarray/core/concat.py index 54bc686a322..0955a95fa8b 100644 --- a/xarray/core/concat.py +++ b/xarray/core/concat.py @@ -349,7 +349,11 @@ def _parse_datasets( all_coord_names.update(ds.coords) data_vars.update(ds.data_vars) - for dim in set(ds.dims) - dims: + # preserves ordering of dimensions + for dim in ds.dims: + if dim in dims: + continue + if dim not in dim_coords: dim_coords[dim] = ds.coords[dim].variable dims = dims | set(ds.dims) diff --git a/xarray/core/coordinates.py b/xarray/core/coordinates.py index a4b8ca478eb..846e4044a2c 100644 --- a/xarray/core/coordinates.py +++ b/xarray/core/coordinates.py @@ -215,7 +215,9 @@ def __getitem__(self, key: Hashable) -> "DataArray": def to_dataset(self) -> "Dataset": """Convert these coordinates into a new Dataset""" - return self._data._copy_listed(self._names) + + names = [name for name in self._data._variables if name in self._names] + return self._data._copy_listed(names) def _update_coords( self, coords: Dict[Hashable, Variable], indexes: Mapping[Hashable, pd.Index] diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 825d2044a12..ce72d4a5886 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -1142,7 +1142,11 @@ def _copy_listed(self, names: Iterable[Hashable]) -> "Dataset": dims = {k: self.dims[k] for k in needed_dims} - for k in self._coord_names: + # preserves ordering of coordinates + for k in self._variables: + if k not in self._coord_names: + continue + if set(self.variables[k].dims) <= needed_dims: variables[k] = self._variables[k] coord_names.add(k) @@ -5729,10 +5733,10 @@ def filter_by_attrs(self, **kwargs): Dimensions: (time: 3, x: 2, y: 2) Coordinates: - reference_time datetime64[ns] 2014-09-05 + lon (x, y) float64 -99.83 -99.32 -99.79 -99.23 lat (x, y) float64 42.25 42.21 42.63 42.59 * time (time) datetime64[ns] 2014-09-06 2014-09-07 2014-09-08 - lon (x, y) float64 -99.83 -99.32 -99.79 -99.23 + reference_time datetime64[ns] 2014-09-05 Dimensions without coordinates: x, y Data variables: precipitation (x, y, time) float64 5.68 9.256 0.7104 ... 7.992 4.615 7.805 @@ -5742,10 +5746,10 @@ def filter_by_attrs(self, **kwargs): Dimensions: (time: 3, x: 2, y: 2) Coordinates: - reference_time datetime64[ns] 2014-09-05 + lon (x, y) float64 -99.83 -99.32 -99.79 -99.23 lat (x, y) float64 42.25 42.21 42.63 42.59 * time (time) datetime64[ns] 2014-09-06 2014-09-07 2014-09-08 - lon (x, y) float64 -99.83 -99.32 -99.79 -99.23 + reference_time datetime64[ns] 2014-09-05 Dimensions without coordinates: x, y Data variables: temperature (x, y, time) float64 29.11 18.2 22.83 ... 18.28 16.15 26.63 diff --git a/xarray/tests/test_testing.py b/xarray/tests/test_testing.py index 0f2ae8b31d4..30ea6aaaee9 100644 --- a/xarray/tests/test_testing.py +++ b/xarray/tests/test_testing.py @@ -70,12 +70,7 @@ def test_assert_allclose(obj1, obj2): pytest.param( quantity, id="pint", - marks=[ - pytest.mark.skipif(not has_pint, reason="requires pint"), - pytest.mark.xfail( - reason="inconsistencies in the return value of pint's implementation of eq" - ), - ], + marks=pytest.mark.skipif(not has_pint, reason="requires pint"), ), ), ) @@ -115,12 +110,7 @@ def test_assert_duckarray_equal_failing(duckarray, obj1, obj2): pytest.param( quantity, id="pint", - marks=[ - pytest.mark.skipif(not has_pint, reason="requires pint"), - pytest.mark.xfail( - reason="inconsistencies in the return value of pint's implementation of eq" - ), - ], + marks=pytest.mark.skipif(not has_pint, reason="requires pint"), ), ), )