Skip to content

Commit 25067cf

Browse files
committed
Merge branch 'feature/expand-dims-broadcast' of https://github.com/pletchm/xarray into feature/expand-dims-broadcast
2 parents 139d625 + df4142b commit 25067cf

33 files changed

+1083
-351
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ matrix:
1919
- EXTRA_FLAGS="--run-flaky --run-network-tests"
2020
- env: CONDA_ENV=py36-dask-dev
2121
- env: CONDA_ENV=py36-pandas-dev
22-
- env: CONDA_ENV=py36-bottleneck-dev
2322
- env: CONDA_ENV=py36-rasterio
2423
- env: CONDA_ENV=py36-zarr-dev
2524
- env: CONDA_ENV=docs
@@ -31,7 +30,6 @@ matrix:
3130
- CONDA_ENV=py36
3231
- EXTRA_FLAGS="--run-flaky --run-network-tests"
3332
- env: CONDA_ENV=py36-pandas-dev
34-
- env: CONDA_ENV=py36-bottleneck-dev
3533
- env: CONDA_ENV=py36-zarr-dev
3634

3735
before_install:

ci/requirements-py36-bottleneck-dev.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

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
@@ -23,6 +23,11 @@ Matplotlib syntax and function names were copied as much as possible, which
2323
makes for an easy transition between the two.
2424
Matplotlib must be installed before xarray can plot.
2525

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

2833
- `Seaborn <http://seaborn.pydata.org/>`_: "provides
@@ -226,7 +231,7 @@ Step plots
226231
~~~~~~~~~~
227232

228233
As an alternative, also a step plot similar to matplotlib's ``plt.step`` can be
229-
made using 1D data.
234+
made using 1D data.
230235

231236
.. ipython:: python
232237
@@ -248,7 +253,7 @@ when plotting data grouped with :py:func:`xarray.Dataset.groupby_bins`.
248253
plt.ylim(-20,30)
249254
@savefig plotting_example_step_groupby.png width=4in
250255
plt.title('Zonal mean temperature')
251-
256+
252257
In this case, the actual boundaries of the bins are used and the ``where`` argument
253258
is ignored.
254259

doc/time-series.rst

Lines changed: 23 additions & 28 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
@@ -309,31 +309,27 @@ For data indexed by a :py:class:`~xarray.CFTimeIndex` xarray currently supports:
309309
310310
da.differentiate('time')
311311
312-
- And serialization:
312+
- Serialization:
313313

314314
.. ipython:: python
315315
316316
da.to_netcdf('example-no-leap.nc')
317317
xr.open_dataset('example-no-leap.nc')
318318
319-
.. note::
320-
321-
While much of the time series functionality that is possible for standard
322-
dates has been implemented for dates from non-standard calendars, there are
323-
still some remaining important features that have yet to be implemented,
324-
for example:
319+
- And resampling along the time dimension for data indexed by a :py:class:`~xarray.CFTimeIndex`:
325320

326-
- Resampling along the time dimension for data indexed by a
327-
:py:class:`~xarray.CFTimeIndex` (:issue:`2191`, :issue:`2458`)
328-
- Built-in plotting of data with :py:class:`cftime.datetime` coordinate axes
329-
(:issue:`2164`).
321+
.. ipython:: python
322+
323+
da.resample(time='81T', closed='right', label='right', base=3).mean()
324+
325+
.. note::
326+
330327

331328
For some use-cases it may still be useful to convert from
332329
a :py:class:`~xarray.CFTimeIndex` to a :py:class:`pandas.DatetimeIndex`,
333-
despite the difference in calendar types (e.g. to allow the use of some
334-
forms of resample with non-standard calendars). The recommended way of
335-
doing this is to use the built-in
336-
:py:meth:`~xarray.CFTimeIndex.to_datetimeindex` method:
330+
despite the difference in calendar types. The recommended way of doing this
331+
is to use the built-in :py:meth:`~xarray.CFTimeIndex.to_datetimeindex`
332+
method:
337333

338334
.. ipython:: python
339335
:okwarning:
@@ -343,14 +339,13 @@ For data indexed by a :py:class:`~xarray.CFTimeIndex` xarray currently supports:
343339
da
344340
datetimeindex = da.indexes['time'].to_datetimeindex()
345341
da['time'] = datetimeindex
346-
da.resample(time='Y').mean('time')
347-
342+
348343
However in this case one should use caution to only perform operations which
349344
do not depend on differences between dates (e.g. differentiation,
350345
interpolation, or upsampling with resample), as these could introduce subtle
351346
and silent errors due to the difference in calendar types between the dates
352-
encoded in your data and the dates stored in memory.
353-
347+
encoded in your data and the dates stored in memory.
348+
354349
.. _Timestamp-valid range: https://pandas.pydata.org/pandas-docs/stable/timeseries.html#timestamp-limitations
355350
.. _ISO 8601-format: https://en.wikipedia.org/wiki/ISO_8601
356351
.. _partial datetime string indexing: https://pandas.pydata.org/pandas-docs/stable/timeseries.html#partial-string-indexing

doc/whats-new.rst

Lines changed: 20 additions & 3 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
@@ -47,20 +53,25 @@ Enhancements
4753
report showing what exactly differs between the two objects (dimensions /
4854
coordinates / variables / attributes) (:issue:`1507`).
4955
By `Benoit Bovy <https://github.com/benbovy>`_.
56+
- Resampling of standard and non-standard calendars indexed by
57+
:py:class:`~xarray.CFTimeIndex` is now possible. (:issue:`2191`).
58+
By `Jwen Fai Low <https://github.com/jwenfai>`_ and
59+
`Spencer Clark <https://github.com/spencerkclark>`_.
5060
- Add ``tolerance`` option to ``resample()`` methods ``bfill``, ``pad``,
5161
``nearest``. (:issue:`2695`)
5262
By `Hauke Schulz <https://github.com/observingClouds>`_.
53-
5463
- :py:meth:`~xarray.DataArray.integrate` and
5564
:py:meth:`~xarray.Dataset.integrate` are newly added.
5665
See :ref:`_compute.using_coordinates` for the detail.
5766
(:issue:`1332`)
5867
By `Keisuke Fujii <https://github.com/fujiisoup>`_.
68+
- :py:meth:`pandas.Series.dropna` is now supported for a
69+
:py:class:`pandas.Series` indexed by a :py:class:`~xarray.CFTimeIndex`
70+
(:issue:`2688`). By `Spencer Clark <https://github.com/spencerkclark>`_.
5971
- Allow ``expand_dims`` method to support inserting/broadcasting dimensions
6072
with size > 1. (:issue:`2710`)
6173
By `Martin Pletcher <https://github.com/pletchm>`_.
6274

63-
6475
Bug fixes
6576
~~~~~~~~~
6677

@@ -77,6 +88,12 @@ Bug fixes
7788
:py:class:`CFTimeIndex` now results in a :py:class:`pandas.TimedeltaIndex`
7889
instead of raising a ``TypeError`` (:issue:`2671`). By `Spencer Clark
7990
<https://github.com/spencerkclark>`_.
91+
- backend_kwargs are no longer ignored when using open_dataset with pynio engine
92+
(:issue:'2380')
93+
By 'Jonathan Joyce <https://github.com/jonmjoyce>'_.
94+
- Fix ``open_rasterio`` creating a WKT CRS instead of PROJ.4 with
95+
``rasterio`` 1.0.14+ (:issue:`2715`).
96+
By `David Hoese <https://github.com/djhoese`_.
8097

8198
.. _whats-new.0.11.3:
8299

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

0 commit comments

Comments
 (0)