Skip to content

Commit

Permalink
raise error if objects other than datasets are passed to save_mfdatas…
Browse files Browse the repository at this point in the history
…et() (#1556)
  • Loading branch information
Joe Hamman committed Sep 7, 2017
1 parent 216bb67 commit 98a05f1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
15 changes: 11 additions & 4 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = _build
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXATUOBUILD = sphinx-autobuild
PAPER =
BUILDDIR = _build

# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
Expand All @@ -18,6 +19,7 @@ I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " livehtml Make standalone HTML files and rebuild the documentation when a change is detected. Also includes a livereload enabled web server"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " singlehtml to make a single large HTML file"
@echo " pickle to make pickle files"
Expand Down Expand Up @@ -56,6 +58,11 @@ html:
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."

.PHONY: livehtml
livehtml:
# @echo "$(SPHINXATUOBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html"
$(SPHINXATUOBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html

.PHONY: dirhtml
dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
Expand Down
22 changes: 15 additions & 7 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ Breaking changes

- Supplying ``coords`` as a dictionary to the ``DataArray`` constructor without
also supplying an explicit ``dims`` argument is no longer supported. This
behavior was deprecated in version 0.9 but is now an error (:issue:`727`).
behavior was deprecated in version 0.9 but will now raise an error
(:issue:`727`).
By `Joe Hamman <https://github.com/jhamman>`_.

Backward Incompatible Changes
Expand Down Expand Up @@ -58,7 +59,7 @@ Enhancements

- More attributes available in :py:attr:`~xarray.Dataset.attrs` dictionary when
raster files are opened with :py:func:`~xarray.open_rasterio`.
By `Greg Brener <https://github.com/gbrener>`_
By `Greg Brener <https://github.com/gbrener>`_.

- Support for NetCDF files using an ``_Unsigned`` attribute to indicate that a
a signed integer data type should be interpreted as unsigned bytes
Expand Down Expand Up @@ -97,23 +98,26 @@ Enhancements
other means (:issue:`1459`).
By `Ryan May <https://github.com/dopplershift>`_.

- Support passing keyword arguments to ``load``, ``compute``, and ``persist``
methods. Any keyword arguments supplied to these methods are passed on to
the corresponding dask function (:issue:`1523`).
By `Joe Hamman <https://github.com/jhamman>`_.
- Support passing keyword arguments to ``load``, ``compute``, and ``persist``
methods. Any keyword arguments supplied to these methods are passed on to
the corresponding dask function (:issue:`1523`).
By `Joe Hamman <https://github.com/jhamman>`_.

- Encoding attributes are now preserved when xarray objects are concatenated.
The encoding is copied from the first object (:issue:`1297`).
By `Joe Hamman <https://github.com/jhamman>`_ and
`Gerrit Holl <https://github.com/gerritholl`_.
`Gerrit Holl <https://github.com/gerritholl>`_.

Bug fixes
~~~~~~~~~

- Fixes to ensure xarray works properly with the upcoming pandas 0.21 release:

- Fix :py:meth:`~xarray.DataArray.isnull` method (:issue:`1549`).
- :py:meth:`~xarray.DataArray.to_series` and
:py:meth:`~xarray.Dataset.to_dataframe` should not return a ``pandas.MultiIndex``
for 1D data (:issue:`1548`).
By `Stephan Hoyer <https://github.com/shoyer>`_.

- :py:func:`~xarray.open_rasterio` method now shifts the rasterio
coordinates so that they are centered in each pixel.
Expand Down Expand Up @@ -146,6 +150,10 @@ Bug fixes
provided (:issue:`1410`).
By `Joe Hamman <https://github.com/jhamman>`_.

- Fix :py:func:`xarray.save_mfdataset` to properly raise an informative error
when objects other than ``Dataset`` are provided (:issue:`1555`).
By `Joe Hamman <https://github.com/jhamman>`_.

.. _whats-new.0.9.6:

v0.9.6 (8 June 2017)
Expand Down
8 changes: 6 additions & 2 deletions xarray/backends/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
from __future__ import division
from __future__ import print_function
import os.path
from distutils.version import LooseVersion
from glob import glob
from io import BytesIO
from numbers import Number


import numpy as np

from .. import backends, conventions
from .. import backends, conventions, Dataset
from .common import ArrayWriter, GLOBAL_LOCK
from ..core import indexing
from ..core.combine import auto_combine
Expand Down Expand Up @@ -656,6 +655,11 @@ def save_mfdataset(datasets, paths, mode='w', format=None, groups=None,
raise ValueError("cannot use mode='w' when writing multiple "
'datasets to the same path')

for obj in datasets:
if not isinstance(obj, Dataset):
raise TypeError('save_mfdataset only supports writing Dataset '
'objects, recieved type %s' % type(obj))

if groups is None:
groups = [None] * len(datasets)

Expand Down
7 changes: 7 additions & 0 deletions xarray/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,13 @@ def test_save_mfdataset_invalid(self):
with self.assertRaisesRegexp(ValueError, 'same length'):
save_mfdataset([ds, ds], ['only one path'])

def test_save_mfdataset_invalid_dataarray(self):
# regression test for GH1555
da = DataArray([1, 2])
with self.assertRaisesRegexp(TypeError, 'supports writing Dataset'):
save_mfdataset([da], ['dataarray'])


@requires_pathlib
def test_save_mfdataset_pathlib_roundtrip(self):
original = Dataset({'foo': ('x', np.random.randn(10))})
Expand Down

0 comments on commit 98a05f1

Please sign in to comment.