Skip to content

Commit 0c20fc8

Browse files
author
dcherian
committed
Merge branch 'master' into yohai-ds_scatter
* master: typo in whats_new (pydata#2763) Update computation.py to use Python 3 function signatures (pydata#2756) add h5netcdf+dask tests (pydata#2737) Fix name loss when masking (pydata#2749) fix datetime_to_numeric and Variable._to_numeric (pydata#2668) Fix mypy errors (pydata#2753) enable internal plotting with cftime datetime (pydata#2665) remove references to cyordereddict (pydata#2750) BUG: Pass kwargs to the FileManager for pynio engine (pydata#2380) (pydata#2732) reintroduce pynio/rasterio/iris to py36 test env (pydata#2738) Fix CRS being WKT instead of PROJ.4 (pydata#2715) Refactor (part of) dataset.py to use explicit indexes (pydata#2696)
2 parents d7e9a0f + 17fa64f commit 0c20fc8

31 files changed

+863
-496
lines changed

ci/requirements-py36.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ dependencies:
2020
- scipy
2121
- seaborn
2222
- toolz
23-
# - rasterio # xref #2683
23+
- rasterio
2424
- bottleneck
2525
- zarr
2626
- pseudonetcdf>=3.0.1
2727
- eccodes
2828
- cdms2
29-
# - pynio # xref #2683
30-
# - iris>=1.10 # xref #2683
29+
- pynio
30+
- iris>=1.10
3131
- pydap
3232
- lxml
3333
- pip:
3434
- cfgrib>=0.9.2
35-
- mypy==0.650
35+
- mypy==0.660

ci/requirements-py37-windows.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ channels:
44
dependencies:
55
- python=3.7
66
- cftime
7+
- nc-time-axis
78
- dask
89
- distributed
910
- h5py

ci/requirements-py37.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ channels:
44
dependencies:
55
- python=3.7
66
- cftime
7+
- nc-time-axis
78
- dask
89
- distributed
910
- h5py

doc/installing.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ For accelerating xarray
4545
- `bottleneck <https://github.com/kwgoodman/bottleneck>`__: speeds up
4646
NaN-skipping and rolling window aggregations by a large factor
4747
(1.1 or later)
48-
- `cyordereddict <https://github.com/shoyer/cyordereddict>`__: speeds up most
49-
internal operations with xarray data structures (for python versions < 3.5)
5048

5149
For parallel computing
5250
~~~~~~~~~~~~~~~~~~~~~~
@@ -63,6 +61,8 @@ For plotting
6361
:ref:`plot-maps`
6462
- `seaborn <https://stanford.edu/~mwaskom/software/seaborn/>`__: for better
6563
color palettes
64+
- `nc-time-axis <https://github.com/SciTools/nc-time-axis>`__: for plotting
65+
cftime.datetime objects (1.2.0 or later)
6666

6767

6868
Instructions
@@ -111,4 +111,4 @@ To run these benchmark tests in a local machine, first install
111111
- `airspeed-velocity <https://asv.readthedocs.io/en/latest/>`__: a tool for benchmarking Python packages over their lifetime.
112112

113113
and run
114-
``asv run # this will install some conda environments in ./.asv/envs``
114+
``asv run # this will install some conda environments in ./.asv/envs``

doc/plotting.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ Matplotlib syntax and function names were copied as much as possible, which
2424
makes for an easy transition between the two.
2525
Matplotlib must be installed before xarray can plot.
2626

27+
To use xarray's plotting capabilities with time coordinates containing
28+
``cftime.datetime`` objects
29+
`nc-time-axis <https://github.com/SciTools/nc-time-axis>`_ v1.2.0 or later
30+
needs to be installed.
31+
2732
For more extensive plotting applications consider the following projects:
2833

2934
- `Seaborn <http://seaborn.pydata.org/>`_: "provides
@@ -237,7 +242,7 @@ It is also possible to make line plots such that the data are on the x-axis and
237242
============
238243

239244
As an alternative, also a step plot similar to matplotlib's ``plt.step`` can be
240-
made using 1D data.
245+
made using 1D data.
241246

242247
.. ipython:: python
243248
@@ -259,7 +264,7 @@ when plotting data grouped with :py:func:`xarray.Dataset.groupby_bins`.
259264
plt.ylim(-20,30)
260265
@savefig plotting_example_step_groupby.png width=4in
261266
plt.title('Zonal mean temperature')
262-
267+
263268
In this case, the actual boundaries of the bins are used and the ``where`` argument
264269
is ignored.
265270

doc/time-series.rst

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ will be used for indexing. :py:class:`~xarray.CFTimeIndex` enables a subset of
7474
the indexing functionality of a :py:class:`pandas.DatetimeIndex` and is only
7575
fully compatible with the standalone version of ``cftime`` (not the version
7676
packaged with earlier versions ``netCDF4``). See :ref:`CFTimeIndex` for more
77-
information.
77+
information.
7878

7979
Datetime indexing
8080
-----------------
@@ -215,7 +215,7 @@ For more examples of using grouped operations on a time dimension, see
215215

216216

217217
.. _CFTimeIndex:
218-
218+
219219
Non-standard calendars and dates outside the Timestamp-valid range
220220
------------------------------------------------------------------
221221

@@ -224,14 +224,14 @@ Through the standalone ``cftime`` library and a custom subclass of
224224
functionality enabled through the standard :py:class:`pandas.DatetimeIndex` for
225225
dates from non-standard calendars commonly used in climate science or dates
226226
using a standard calendar, but outside the `Timestamp-valid range`_
227-
(approximately between years 1678 and 2262).
227+
(approximately between years 1678 and 2262).
228228

229229
.. note::
230230

231231
As of xarray version 0.11, by default, :py:class:`cftime.datetime` objects
232232
will be used to represent times (either in indexes, as a
233-
:py:class:`~xarray.CFTimeIndex`, or in data arrays with dtype object) if
234-
any of the following are true:
233+
:py:class:`~xarray.CFTimeIndex`, or in data arrays with dtype object) if
234+
any of the following are true:
235235

236236
- The dates are from a non-standard calendar
237237
- Any dates are outside the Timestamp-valid range.
@@ -252,7 +252,7 @@ coordinate with dates from a no-leap calendar and a
252252
dates = [DatetimeNoLeap(year, month, 1) for year, month in
253253
product(range(1, 3), range(1, 13))]
254254
da = xr.DataArray(np.arange(24), coords=[dates], dims=['time'], name='foo')
255-
255+
256256
xarray also includes a :py:func:`~xarray.cftime_range` function, which enables
257257
creating a :py:class:`~xarray.CFTimeIndex` with regularly-spaced dates. For
258258
instance, we can create the same dates and DataArray we created above using:
@@ -261,20 +261,20 @@ instance, we can create the same dates and DataArray we created above using:
261261
262262
dates = xr.cftime_range(start='0001', periods=24, freq='MS', calendar='noleap')
263263
da = xr.DataArray(np.arange(24), coords=[dates], dims=['time'], name='foo')
264-
264+
265265
For data indexed by a :py:class:`~xarray.CFTimeIndex` xarray currently supports:
266266

267267
- `Partial datetime string indexing`_ using strictly `ISO 8601-format`_ partial
268268
datetime strings:
269-
269+
270270
.. ipython:: python
271271
272272
da.sel(time='0001')
273273
da.sel(time=slice('0001-05', '0002-02'))
274274
275275
- Access of basic datetime components via the ``dt`` accessor (in this case
276276
just "year", "month", "day", "hour", "minute", "second", "microsecond",
277-
"season", "dayofyear", and "dayofweek"):
277+
"season", "dayofyear", and "dayofweek"):
278278

279279
.. ipython:: python
280280
@@ -323,14 +323,7 @@ For data indexed by a :py:class:`~xarray.CFTimeIndex` xarray currently supports:
323323
da.resample(time='81T', closed='right', label='right', base=3).mean()
324324
325325
.. note::
326-
327-
While much of the time series functionality that is possible for standard
328-
dates has been implemented for dates from non-standard calendars, there are
329-
still some remaining important features that have yet to be implemented,
330-
for example:
331-
332-
- Built-in plotting of data with :py:class:`cftime.datetime` coordinate axes
333-
(:issue:`2164`).
326+
334327

335328
For some use-cases it may still be useful to convert from
336329
a :py:class:`~xarray.CFTimeIndex` to a :py:class:`pandas.DatetimeIndex`,
@@ -351,8 +344,8 @@ For data indexed by a :py:class:`~xarray.CFTimeIndex` xarray currently supports:
351344
do not depend on differences between dates (e.g. differentiation,
352345
interpolation, or upsampling with resample), as these could introduce subtle
353346
and silent errors due to the difference in calendar types between the dates
354-
encoded in your data and the dates stored in memory.
355-
347+
encoded in your data and the dates stored in memory.
348+
356349
.. _Timestamp-valid range: https://pandas.pydata.org/pandas-docs/stable/timeseries.html#timestamp-limitations
357350
.. _ISO 8601-format: https://en.wikipedia.org/wiki/ISO_8601
358351
.. _partial datetime string indexing: https://pandas.pydata.org/pandas-docs/stable/timeseries.html#partial-string-indexing

doc/whats-new.rst

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,20 @@ Breaking changes
2424
- Remove support for Python 2. This is the first version of xarray that is
2525
Python 3 only. (:issue:`1876`).
2626
By `Joe Hamman <https://github.com/jhamman>`_.
27-
- The `compat` argument to `Dataset` and the `encoding` argument to
27+
- The `compat` argument to `Dataset` and the `encoding` argument to
2828
`DataArray` are deprecated and will be removed in a future release.
2929
(:issue:`1188`)
3030
By `Maximilian Roos <https://github.com/max-sixty>`_.
31+
- `cyordereddict` is no longer used as an optional dependency (:issue:`2744`).
32+
By `Joe Hamman <https://github.com/jhamman>`_.
3133

3234
Enhancements
3335
~~~~~~~~~~~~
3436

37+
- Internal plotting now supports ``cftime.datetime`` objects as time series.
38+
(:issue:`2164`)
39+
By `Julius Busecke <https://github.com/jbusecke>`_ and
40+
`Spencer Clark <https://github.com/spencerkclark>`_.
3541
- Add ``data=False`` option to ``to_dict()`` methods. (:issue:`2656`)
3642
By `Ryan Abernathey <https://github.com/rabernat>`_
3743
- :py:meth:`~xarray.DataArray.coarsen` and
@@ -81,7 +87,15 @@ Bug fixes
8187
:py:class:`CFTimeIndex` now results in a :py:class:`pandas.TimedeltaIndex`
8288
instead of raising a ``TypeError`` (:issue:`2671`). By `Spencer Clark
8389
<https://github.com/spencerkclark>`_.
84-
90+
- backend_kwargs are no longer ignored when using open_dataset with pynio engine
91+
(:issue:'2380')
92+
By 'Jonathan Joyce <https://github.com/jonmjoyce>'_.
93+
- Fix ``open_rasterio`` creating a WKT CRS instead of PROJ.4 with
94+
``rasterio`` 1.0.14+ (:issue:`2715`).
95+
By `David Hoese <https://github.com/djhoese>`_.
96+
- Masking data arrays with :py:meth:`xarray.DataArray.where` now returns an
97+
array with the name of the original masked array (:issue:`2748` and :issue:`2457`).
98+
By `Yohai Bar-Sinai <https://github.com/yohai>`_.
8599
.. _whats-new.0.11.3:
86100

87101
v0.11.3 (26 January 2019)

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ ignore_missing_imports = True
4545
ignore_missing_imports = True
4646
[mypy-Nio.*]
4747
ignore_missing_imports = True
48+
[mypy-nc_time_axis.*]
49+
ignore_missing_imports = True
4850
[mypy-numpy.*]
4951
ignore_missing_imports = True
5052
[mypy-netCDF4.*]

xarray/backends/pynio_.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ class NioDataStore(AbstractDataStore):
4545
"""Store for accessing datasets via PyNIO
4646
"""
4747

48-
def __init__(self, filename, mode='r', lock=None):
48+
def __init__(self, filename, mode='r', lock=None, **kwargs):
4949
import Nio
5050
if lock is None:
5151
lock = PYNIO_LOCK
5252
self.lock = ensure_lock(lock)
5353
self._manager = CachingFileManager(
54-
Nio.open_file, filename, lock=lock, mode=mode)
54+
Nio.open_file, filename, lock=lock, mode=mode, kwargs=kwargs)
5555
# xarray provides its own support for FillValue,
5656
# so turn off PyNIO's support for the same.
5757
self.ds.set_option('MaskedArrayMode', 'MaskedNever')

xarray/backends/rasterio_.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,10 @@ def open_rasterio(filename, parse_coordinates=None, chunks=None, cache=None,
282282
# CRS is a dict-like object specific to rasterio
283283
# If CRS is not None, we convert it back to a PROJ4 string using
284284
# rasterio itself
285-
attrs['crs'] = riods.crs.to_string()
285+
try:
286+
attrs['crs'] = riods.crs.to_proj4()
287+
except AttributeError:
288+
attrs['crs'] = riods.crs.to_string()
286289
if hasattr(riods, 'res'):
287290
# (width, height) tuple of pixels in units of CRS
288291
attrs['res'] = riods.res

xarray/core/alignment.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
import warnings
44
from collections import OrderedDict, defaultdict
55
from contextlib import suppress
6+
from typing import Any, Mapping, Optional, Tuple
67

78
import numpy as np
9+
import pandas as pd
810

911
from . import utils
1012
from .indexing import get_indexer_nd
1113
from .utils import is_dict_like, is_full_slice
12-
from .variable import IndexVariable
14+
from .variable import IndexVariable, Variable
1315

1416

1517
def _get_joiner(join):
@@ -260,8 +262,15 @@ def reindex_like_indexers(target, other):
260262
return indexers
261263

262264

263-
def reindex_variables(variables, sizes, indexes, indexers, method=None,
264-
tolerance=None, copy=True):
265+
def reindex_variables(
266+
variables: Mapping[Any, Variable],
267+
sizes: Mapping[Any, int],
268+
indexes: Mapping[Any, pd.Index],
269+
indexers: Mapping,
270+
method: Optional[str] = None,
271+
tolerance: Any = None,
272+
copy: bool = True,
273+
) -> 'Tuple[OrderedDict[Any, Variable], OrderedDict[Any, pd.Index]]':
265274
"""Conform a dictionary of aligned variables onto a new set of variables,
266275
filling in missing values with NaN.
267276
@@ -274,7 +283,7 @@ def reindex_variables(variables, sizes, indexes, indexers, method=None,
274283
sizes : dict-like
275284
Dictionary from dimension names to integer sizes.
276285
indexes : dict-like
277-
Dictionary of xarray.IndexVariable objects associated with variables.
286+
Dictionary of indexes associated with variables.
278287
indexers : dict
279288
Dictionary with keys given by dimension names and values given by
280289
arrays of coordinates tick labels. Any mis-matched coordinate values
@@ -300,13 +309,15 @@ def reindex_variables(variables, sizes, indexes, indexers, method=None,
300309
Returns
301310
-------
302311
reindexed : OrderedDict
303-
Another dict, with the items in variables but replaced indexes.
312+
Dict of reindexed variables.
313+
new_indexes : OrderedDict
314+
Dict of indexes associated with the reindexed variables.
304315
"""
305316
from .dataarray import DataArray
306317

307318
# build up indexers for assignment along each dimension
308319
int_indexers = {}
309-
targets = {}
320+
targets = OrderedDict() # type: OrderedDict[Any, pd.Index]
310321
masked_dims = set()
311322
unchanged_dims = set()
312323

@@ -346,7 +357,7 @@ def reindex_variables(variables, sizes, indexes, indexers, method=None,
346357
'the new index %r' % (dim, existing_size, new_size))
347358

348359
# create variables for the new dataset
349-
reindexed = OrderedDict()
360+
reindexed = OrderedDict() # type: OrderedDict[Any, Variable]
350361

351362
for dim, indexer in indexers.items():
352363
if isinstance(indexer, DataArray) and indexer.dims != (dim,):
@@ -359,7 +370,7 @@ def reindex_variables(variables, sizes, indexes, indexers, method=None,
359370

360371
if dim in variables:
361372
var = variables[dim]
362-
args = (var.attrs, var.encoding)
373+
args = (var.attrs, var.encoding) # type: tuple
363374
else:
364375
args = ()
365376
reindexed[dim] = IndexVariable((dim,), indexers[dim], *args)
@@ -384,7 +395,10 @@ def reindex_variables(variables, sizes, indexes, indexers, method=None,
384395

385396
reindexed[name] = new_var
386397

387-
return reindexed
398+
new_indexes = OrderedDict(indexes)
399+
new_indexes.update(targets)
400+
401+
return reindexed, new_indexes
388402

389403

390404
def broadcast(*args, **kwargs):

xarray/core/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ def resample(self, indexer=None, skipna=None, closed=None, label=None,
713713
array([ 0. , 0.032258, 0.064516, ..., 10.935484, 10.967742, 11. ])
714714
Coordinates:
715715
* time (time) datetime64[ns] 1999-12-15 1999-12-16 1999-12-17 ...
716-
716+
717717
Limit scope of upsampling method
718718
>>> da.resample(time='1D').nearest(tolerance='1D')
719719
<xarray.DataArray (time: 337)>

0 commit comments

Comments
 (0)