Skip to content

Commit 3038caa

Browse files
committed
Merge remote-tracking branch 'upstream/master' into chunk-unique-token
* upstream/master: Fix map_blocks HLG layering (pydata#3598) Silence sphinx warnings: Round 2 (pydata#3592) 2x~5x speed up for isel() in most cases (pydata#3533) remove xarray again (pydata#3591) fix plotting with transposed nondim coords. (pydata#3441) make coarsen reductions consistent with reductions on other classes (pydata#3500) Resolve the version issues on RTD (pydata#3589) Add bottleneck & rasterio git tip to upstream-dev CI (pydata#3585)
2 parents f0d73e1 + cafcaee commit 3038caa

25 files changed

+294
-98
lines changed

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,5 @@ jobs:
110110
- bash: |
111111
source activate xarray-tests
112112
cd doc
113-
sphinx-build -n -j auto -b html -d _build/doctrees . _build/html
113+
sphinx-build -W --keep-going -j auto -b html -d _build/doctrees . _build/html
114114
displayName: Build HTML docs

ci/azure/install.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ steps:
2525
git+https://github.com/dask/dask \
2626
git+https://github.com/dask/distributed \
2727
git+https://github.com/zarr-developers/zarr \
28-
git+https://github.com/Unidata/cftime
28+
git+https://github.com/Unidata/cftime \
29+
git+https://github.com/mapbox/rasterio \
30+
git+https://github.com/pydata/bottleneck
2931
condition: eq(variables['UPSTREAM_DEV'], 'true')
3032
displayName: Install upstream dev dependencies
3133

ci/requirements/doc.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ dependencies:
66
- python=3.7
77
- bottleneck
88
- cartopy
9-
- eccodes
9+
- cfgrib
1010
- h5netcdf
1111
- ipykernel
1212
- ipython
@@ -22,7 +22,3 @@ dependencies:
2222
- sphinx
2323
- sphinx_rtd_theme
2424
- zarr
25-
- pip
26-
- pip:
27-
- cfgrib
28-

doc/conf.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,16 @@
1515

1616
import datetime
1717
import os
18+
import pathlib
1819
import subprocess
1920
import sys
2021
from contextlib import suppress
2122

23+
# make sure the source version is preferred (#3567)
24+
root = pathlib.Path(__file__).absolute().parent.parent
25+
os.environ["PYTHONPATH"] = str(root)
26+
sys.path.insert(0, str(root))
27+
2228
import xarray
2329

2430
allowed_failures = set()

doc/whats-new.rst

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ New Features
2828
- :py:meth:`Dataset.quantile`, :py:meth:`DataArray.quantile` and ``GroupBy.quantile``
2929
now work with dask Variables.
3030
By `Deepak Cherian <https://github.com/dcherian>`_.
31-
31+
- Added the :py:meth:`count` reduction method to both :py:class:`DatasetCoarsen`
32+
and :py:class:`DataArrayCoarsen` objects. (:pull:`3500`)
33+
By `Deepak Cherian <https://github.com/dcherian>`_
3234

3335
Bug fixes
3436
~~~~~~~~~
@@ -37,29 +39,35 @@ Bug fixes
3739
stay the same when rechunking by the same chunk size. (:issue:`3350`)
3840
By `Deepak Cherian <https://github.com/dcherian>`_.
3941

42+
- Fix plotting with transposed 2D non-dimensional coordinates. (:issue:`3138`, :pull:`3441`)
43+
By `Deepak Cherian <https://github.com/dcherian>`_.
44+
- Fix issue with Dask-backed datasets raising a ``KeyError`` on some computations involving ``map_blocks`` (:pull:`3598`)
45+
By `Tom Augspurger <https://github.com/TomAugspurger>`_.
4046

4147
Documentation
4248
~~~~~~~~~~~~~
4349
- Switch doc examples to use nbsphinx and replace sphinx_gallery with
4450
notebook.
4551
(:pull:`3105`, :pull:`3106`, :pull:`3121`)
46-
By `Ryan Abernathey <https://github.com/rabernat>`
52+
By `Ryan Abernathey <https://github.com/rabernat>`_
4753
- Added example notebook demonstrating use of xarray with Regional Ocean
4854
Modeling System (ROMS) ocean hydrodynamic model output.
4955
(:pull:`3116`).
50-
By `Robert Hetland <https://github.com/hetland>`
56+
By `Robert Hetland <https://github.com/hetland>`_
5157
- Added example notebook demonstrating the visualization of ERA5 GRIB
5258
data. (:pull:`3199`)
53-
By `Zach Bruick <https://github.com/zbruick>` and
54-
`Stephan Siemen <https://github.com/StephanSiemen>`
55-
- Added examples for `DataArray.quantile`, `Dataset.quantile` and
56-
`GroupBy.quantile`. (:pull:`3576`)
59+
By `Zach Bruick <https://github.com/zbruick>`_ and
60+
`Stephan Siemen <https://github.com/StephanSiemen>`_
61+
- Added examples for :py:meth:`DataArray.quantile`, :py:meth:`Dataset.quantile` and
62+
``GroupBy.quantile``. (:pull:`3576`)
5763
By `Justus Magin <https://github.com/keewis>`_.
5864

5965
Internal Changes
6066
~~~~~~~~~~~~~~~~
61-
62-
67+
- 2x to 5x speed boost (on small arrays) for :py:meth:`Dataset.isel`,
68+
:py:meth:`DataArray.isel`, and :py:meth:`DataArray.__getitem__` when indexing by int,
69+
slice, list of int, scalar ndarray, or 1-dimensional ndarray.
70+
(:pull:`3533`) by `Guido Imperiale <https://github.com/crusaderky>`_.
6371
- Removed internal method ``Dataset._from_vars_and_coord_names``,
6472
which was dominated by ``Dataset._construct_direct``. (:pull:`3565`)
6573
By `Maximilian Roos <https://github.com/max-sixty>`_
@@ -190,6 +198,7 @@ Documentation
190198

191199
Internal Changes
192200
~~~~~~~~~~~~~~~~
201+
193202
- Added integration tests against `pint <https://pint.readthedocs.io/>`_.
194203
(:pull:`3238`, :pull:`3447`, :pull:`3493`, :pull:`3508`)
195204
by `Justus Magin <https://github.com/keewis>`_.

readthedocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ conda:
44
file: ci/requirements/doc.yml
55
python:
66
version: 3.7
7-
setup_py_install: true
7+
setup_py_install: false
88
formats: []

xarray/coding/cftime_offsets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
import re
4444
from datetime import timedelta
45+
from distutils.version import LooseVersion
4546
from functools import partial
4647
from typing import ClassVar, Optional
4748

@@ -50,7 +51,6 @@
5051
from ..core.pdcompat import count_not_none
5152
from .cftimeindex import CFTimeIndex, _parse_iso8601_with_reso
5253
from .times import format_cftime_datetime
53-
from distutils.version import LooseVersion
5454

5555

5656
def get_date_type(calendar):

xarray/core/dataarray.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
)
5151
from .dataset import Dataset, split_indexes
5252
from .formatting import format_item
53-
from .indexes import Indexes, propagate_indexes, default_indexes
53+
from .indexes import Indexes, default_indexes, propagate_indexes
54+
from .indexing import is_fancy_indexer
5455
from .merge import PANDAS_TYPES, _extract_indexes_from_coords
5556
from .options import OPTIONS
5657
from .utils import Default, ReprObject, _check_inplace, _default, either_dict_or_kwargs
@@ -234,19 +235,6 @@ class DataArray(AbstractArray, DataWithCoords):
234235
235236
Getting items from or doing mathematical operations with a DataArray
236237
always returns another DataArray.
237-
238-
Attributes
239-
----------
240-
dims : tuple
241-
Dimension names associated with this array.
242-
values : numpy.ndarray
243-
Access or modify DataArray values as a numpy array.
244-
coords : dict-like
245-
Dictionary of DataArray objects that label values along each dimension.
246-
name : str or None
247-
Name of this array.
248-
attrs : dict
249-
Dictionary for holding arbitrary metadata.
250238
"""
251239

252240
_cache: Dict[str, Any]
@@ -1027,8 +1015,27 @@ def isel(
10271015
DataArray.sel
10281016
"""
10291017
indexers = either_dict_or_kwargs(indexers, indexers_kwargs, "isel")
1030-
ds = self._to_temp_dataset().isel(drop=drop, indexers=indexers)
1031-
return self._from_temp_dataset(ds)
1018+
if any(is_fancy_indexer(idx) for idx in indexers.values()):
1019+
ds = self._to_temp_dataset()._isel_fancy(indexers, drop=drop)
1020+
return self._from_temp_dataset(ds)
1021+
1022+
# Much faster algorithm for when all indexers are ints, slices, one-dimensional
1023+
# lists, or zero or one-dimensional np.ndarray's
1024+
1025+
variable = self._variable.isel(indexers)
1026+
1027+
coords = {}
1028+
for coord_name, coord_value in self._coords.items():
1029+
coord_indexers = {
1030+
k: v for k, v in indexers.items() if k in coord_value.dims
1031+
}
1032+
if coord_indexers:
1033+
coord_value = coord_value.isel(coord_indexers)
1034+
if drop and coord_value.ndim == 0:
1035+
continue
1036+
coords[coord_name] = coord_value
1037+
1038+
return self._replace(variable=variable, coords=coords)
10321039

10331040
def sel(
10341041
self,
@@ -2980,8 +2987,6 @@ def quantile(
29802987
... coords={"x": [7, 9], "y": [1, 1.5, 2, 2.5]},
29812988
... dims=("x", "y"),
29822989
... )
2983-
2984-
Single quantile
29852990
>>> da.quantile(0) # or da.quantile(0, dim=...)
29862991
<xarray.DataArray ()>
29872992
array(0.7)
@@ -2993,8 +2998,6 @@ def quantile(
29932998
Coordinates:
29942999
* y (y) float64 1.0 1.5 2.0 2.5
29953000
quantile float64 0.0
2996-
2997-
Multiple quantiles
29983001
>>> da.quantile([0, 0.5, 1])
29993002
<xarray.DataArray (quantile: 3)>
30003003
array([0.7, 3.4, 9.4])

xarray/core/dataset.py

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
propagate_indexes,
6767
roll_index,
6868
)
69+
from .indexing import is_fancy_indexer
6970
from .merge import (
7071
dataset_merge_method,
7172
dataset_update_method,
@@ -78,8 +79,8 @@
7879
Default,
7980
Frozen,
8081
SortedKeysDict,
81-
_default,
8282
_check_inplace,
83+
_default,
8384
decode_numpy_dict_values,
8485
either_dict_or_kwargs,
8586
hashable,
@@ -1910,6 +1911,48 @@ def isel(
19101911
DataArray.isel
19111912
"""
19121913
indexers = either_dict_or_kwargs(indexers, indexers_kwargs, "isel")
1914+
if any(is_fancy_indexer(idx) for idx in indexers.values()):
1915+
return self._isel_fancy(indexers, drop=drop)
1916+
1917+
# Much faster algorithm for when all indexers are ints, slices, one-dimensional
1918+
# lists, or zero or one-dimensional np.ndarray's
1919+
invalid = indexers.keys() - self.dims.keys()
1920+
if invalid:
1921+
raise ValueError("dimensions %r do not exist" % invalid)
1922+
1923+
variables = {}
1924+
dims: Dict[Hashable, Tuple[int, ...]] = {}
1925+
coord_names = self._coord_names.copy()
1926+
indexes = self._indexes.copy() if self._indexes is not None else None
1927+
1928+
for var_name, var_value in self._variables.items():
1929+
var_indexers = {k: v for k, v in indexers.items() if k in var_value.dims}
1930+
if var_indexers:
1931+
var_value = var_value.isel(var_indexers)
1932+
if drop and var_value.ndim == 0 and var_name in coord_names:
1933+
coord_names.remove(var_name)
1934+
if indexes:
1935+
indexes.pop(var_name, None)
1936+
continue
1937+
if indexes and var_name in indexes:
1938+
if var_value.ndim == 1:
1939+
indexes[var_name] = var_value.to_index()
1940+
else:
1941+
del indexes[var_name]
1942+
variables[var_name] = var_value
1943+
dims.update(zip(var_value.dims, var_value.shape))
1944+
1945+
return self._construct_direct(
1946+
variables=variables,
1947+
coord_names=coord_names,
1948+
dims=dims,
1949+
attrs=self._attrs,
1950+
indexes=indexes,
1951+
encoding=self._encoding,
1952+
file_obj=self._file_obj,
1953+
)
1954+
1955+
def _isel_fancy(self, indexers: Mapping[Hashable, Any], *, drop: bool) -> "Dataset":
19131956
# Note: we need to preserve the original indexers variable in order to merge the
19141957
# coords below
19151958
indexers_list = list(self._validate_indexers(indexers))
@@ -5127,8 +5170,6 @@ def quantile(
51275170
... {"a": (("x", "y"), [[0.7, 4.2, 9.4, 1.5], [6.5, 7.3, 2.6, 1.9]])},
51285171
... coords={"x": [7, 9], "y": [1, 1.5, 2, 2.5]},
51295172
... )
5130-
5131-
Single quantile
51325173
>>> ds.quantile(0) # or ds.quantile(0, dim=...)
51335174
<xarray.Dataset>
51345175
Dimensions: ()
@@ -5144,8 +5185,6 @@ def quantile(
51445185
quantile float64 0.0
51455186
Data variables:
51465187
a (y) float64 0.7 4.2 2.6 1.5
5147-
5148-
Multiple quantiles
51495188
>>> ds.quantile([0, 0.5, 1])
51505189
<xarray.Dataset>
51515190
Dimensions: (quantile: 3)

xarray/core/formatting_html.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import uuid
2-
import pkg_resources
32
from collections import OrderedDict
43
from functools import partial
54
from html import escape
65

7-
from .formatting import inline_variable_array_repr, short_data_repr
6+
import pkg_resources
87

8+
from .formatting import inline_variable_array_repr, short_data_repr
99

1010
CSS_FILE_PATH = "/".join(("static", "css", "style.css"))
1111
CSS_STYLE = pkg_resources.resource_string("xarray", CSS_FILE_PATH).decode("utf8")

0 commit comments

Comments
 (0)