Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ Breaking changes
[...]

Note that both versions are currently supported, but using the old syntax will
produce a warning encouraging users to adopt the new syntax.
produce a warning encouraging users to adopt the new syntax.
By `Daniel Rothenberg <https://github.com/darothen>`_.

- ``repr`` and the Jupyter Notebook won't automatically compute dask variables.
Datasets loaded with ``open_dataset`` won't automatically read coords from
disk when calling ``repr`` (:issue:`1522`).
Expand Down Expand Up @@ -212,6 +212,11 @@ Bug fixes
the first argument was a numpy variable (:issue:`1588`).
By `Guido Imperiale <https://github.com/crusaderky>`_.

- Fix bug when using ``pytest`` class decorators to skiping certain unittests.
The previous behavior unintentionally causing additional tests to be skipped.
A temporary work-around has been applied in :issue:`1531`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is temporary for xarray, but from a user (or distributor) perspective the bug is fixed. I would probably drop that part.

By `Joe Hamman <https://github.com/jhamman>`_.

.. _whats-new.0.9.6:

v0.9.6 (8 June 2017)
Expand Down
1 change: 0 additions & 1 deletion xarray/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from distutils.version import LooseVersion
import re
import importlib
import types

import numpy as np
from numpy.testing import assert_array_equal
Expand Down
4 changes: 4 additions & 0 deletions xarray/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,10 @@ def test_weakrefs(self):
class TestPyNioAutocloseTrue(TestPyNio):
autoclose = True

@requires_pynio
def setUp(self):
pass

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to be working. I'll try to come up with something else but if anyone has any ideas for how to get around this, I'm all ears.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it work if you hand-write the test-skipping decorator to raise unittest.SkipTest rather than relying on pytest.mark.skipif?


class TestRasterio(TestCase):

Expand Down
13 changes: 10 additions & 3 deletions xarray/tests/test_conventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,8 @@ def test(self):
self.assertArrayEqual(a, expected)


@requires_netCDF4
class TestEncodeCFVariable(TestCase):
@requires_netCDF4
def test_incompatible_attributes(self):
invalid_vars = [
Variable(['t'], pd.date_range('2000-01-01', periods=3),
Expand All @@ -541,15 +541,16 @@ def test_incompatible_attributes(self):
with self.assertRaises(ValueError):
conventions.encode_cf_variable(var)

@requires_netCDF4
def test_missing_fillvalue(self):
v = Variable(['x'], np.array([np.nan, 1, 2, 3]))
v.encoding = {'dtype': 'int16'}
with self.assertWarns('floating point data as an integer'):
conventions.encode_cf_variable(v)


@requires_netCDF4
class TestDecodeCF(TestCase):
@requires_netCDF4
def test_dataset(self):
original = Dataset({
't': ('t', [0, 1, 2], {'units': 'days since 2000-01-01'}),
Expand All @@ -562,25 +563,30 @@ def test_dataset(self):
actual = conventions.decode_cf(original)
self.assertDatasetIdentical(expected, actual)

@requires_netCDF4
def test_invalid_coordinates(self):
# regression test for GH308
original = Dataset({'foo': ('t', [1, 2], {'coordinates': 'invalid'})})
actual = conventions.decode_cf(original)
self.assertDatasetIdentical(original, actual)

@requires_netCDF4
def test_decode_coordinates(self):

# regression test for GH610
original = Dataset({'foo': ('t', [1, 2], {'coordinates': 'x'}),
'x': ('t', [4, 5])})
actual = conventions.decode_cf(original)
self.assertEqual(actual.foo.encoding['coordinates'], 'x')

@requires_netCDF4
def test_0d_int32_encoding(self):
original = Variable((), np.int32(0), encoding={'dtype': 'int64'})
expected = Variable((), np.int64(0))
actual = conventions.maybe_encode_dtype(original)
self.assertDatasetIdentical(expected, actual)

@requires_netCDF4
def test_decode_cf_with_multiple_missing_values(self):
original = Variable(['t'], [0, 1, 2],
{'missing_value': np.array([0, 1])})
Expand All @@ -590,6 +596,7 @@ def test_decode_cf_with_multiple_missing_values(self):
self.assertDatasetIdentical(expected, actual)
self.assertIn('variable has multiple fill', str(w[0].message))

@requires_netCDF4
def test_decode_cf_with_drop_variables(self):
original = Dataset({
't': ('t', [0, 1, 2], {'units': 'days since 2000-01-01'}),
Expand Down Expand Up @@ -634,13 +641,13 @@ def null_wrap(ds):
return InMemoryDataStore(variables=variables, attributes=ds.attrs)


@requires_netCDF4
class TestCFEncodedDataStore(CFEncodedDataTest, TestCase):
@contextlib.contextmanager
def create_store(self):
yield CFEncodedInMemoryStore()

@contextlib.contextmanager
@requires_netCDF4
def roundtrip(self, data, save_kwargs={}, open_kwargs={},
allow_cleanup_failure=False):
store = CFEncodedInMemoryStore()
Expand Down
4 changes: 2 additions & 2 deletions xarray/tests/test_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ def assertLazyAnd(self, expected, actual, test):
assert False


@requires_dask
class TestVariable(DaskTestCase):
def assertLazyAndIdentical(self, expected, actual):
self.assertLazyAnd(expected, actual, self.assertVariableIdentical)

def assertLazyAndAllClose(self, expected, actual):
self.assertLazyAnd(expected, actual, self.assertVariableAllClose)

@requires_dask
def setUp(self):
self.values = np.random.RandomState(0).randn(4, 6)
self.data = da.from_array(self.values, chunks=(2, 2))
Expand Down Expand Up @@ -206,7 +206,6 @@ def test_bivariate_ufunc(self):
self.assertLazyAndAllClose(np.maximum(u, 0), xu.maximum(0, v))


@requires_dask
class TestDataArrayAndDataset(DaskTestCase):
def assertLazyAndIdentical(self, expected, actual):
self.assertLazyAnd(expected, actual, self.assertDataArrayIdentical)
Expand All @@ -217,6 +216,7 @@ def assertLazyAndAllClose(self, expected, actual):
def assertLazyAndEqual(self, expected, actual):
self.assertLazyAnd(expected, actual, self.assertDataArrayEqual)

@requires_dask
def setUp(self):
self.values = np.random.randn(4, 6)
self.data = da.from_array(self.values, chunks=(2, 2))
Expand Down
4 changes: 2 additions & 2 deletions xarray/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_consolidate_slices():
assert _consolidate_slices([slice(3), slice(3, 5)]) == [slice(5)]
assert _consolidate_slices([slice(2, 3), slice(3, 6)]) == [slice(2, 6)]
assert (_consolidate_slices([slice(2, 3, 1), slice(3, 6, 1)])
== [slice(2, 6, 1)])
== [slice(2, 6, 1)])

slices = [slice(2, 3), slice(5, 6)]
assert _consolidate_slices(slices) == slices
Expand Down Expand Up @@ -70,5 +70,5 @@ def test_groupby_duplicate_coordinate_labels():
actual = array.groupby('x').sum()
assert expected.equals(actual)


# TODO: move other groupby tests from test_dataset and test_dataarray over here
12 changes: 9 additions & 3 deletions xarray/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def easy_array(shape, start=0, stop=1):
return a.reshape(shape)


@requires_matplotlib
class PlotTestCase(TestCase):

def tearDown(self):
Expand All @@ -91,6 +90,7 @@ def contourf_called(self, plotmethod):

class TestPlot(PlotTestCase):

@requires_matplotlib
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to move the requires_matplotlib decorator, since we don't rely on inheritance for enabling/disabling tests.

def setUp(self):
self.darray = DataArray(easy_array((2, 3, 4)))

Expand Down Expand Up @@ -219,6 +219,7 @@ def test_convenient_facetgrid_4d(self):

class TestPlot1D(PlotTestCase):

@requires_matplotlib
def setUp(self):
d = [0, 1.1, 0, 2]
self.darray = DataArray(d, coords={'period': range(len(d))},
Expand Down Expand Up @@ -279,6 +280,7 @@ def test_slice_in_title(self):

class TestPlotHistogram(PlotTestCase):

@requires_matplotlib
def setUp(self):
self.darray = DataArray(easy_array((2, 3, 4)))

Expand Down Expand Up @@ -316,9 +318,9 @@ def test_plot_nans(self):
self.darray.plot.hist()


@requires_matplotlib
class TestDetermineCmapParams(TestCase):

@requires_matplotlib
def setUp(self):
self.data = np.linspace(0, 1, num=100)

Expand Down Expand Up @@ -467,9 +469,9 @@ def test_divergentcontrol(self):
self.assertEqual(cmap_params['cmap'].name, "viridis")


@requires_matplotlib
class TestDiscreteColorMap(TestCase):

@requires_matplotlib
def setUp(self):
x = np.arange(start=0, stop=10, step=2)
y = np.arange(start=9, stop=-7, step=-3)
Expand Down Expand Up @@ -559,6 +561,7 @@ class Common2dMixin:
Should have the same name as the method.
"""

@requires_matplotlib
def setUp(self):
da = DataArray(easy_array(
(10, 15), start=-1), dims=['y', 'x'])
Expand Down Expand Up @@ -1019,6 +1022,7 @@ def test_2d_coord_names(self):

class TestFacetGrid(PlotTestCase):

@requires_matplotlib
def setUp(self):
d = easy_array((10, 15, 3))
self.darray = DataArray(d, dims=['y', 'x', 'z'],
Expand Down Expand Up @@ -1242,6 +1246,7 @@ def test_facetgrid_polar(self):

class TestFacetGrid4d(PlotTestCase):

@requires_matplotlib
def setUp(self):
a = easy_array((10, 15, 3, 2))
darray = DataArray(a, dims=['y', 'x', 'col', 'row'])
Expand Down Expand Up @@ -1270,6 +1275,7 @@ def test_default_labels(self):

class TestDatetimePlot(PlotTestCase):

@requires_matplotlib
def setUp(self):
'''
Create a DataArray with a time-axis that contains datetime objects.
Expand Down
3 changes: 1 addition & 2 deletions xarray/tests/test_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
from __future__ import print_function

import os
import pytest

from xarray import tutorial, DataArray
from xarray.core.pycompat import suppress

from . import TestCase, network


@network
class TestLoadDataset(TestCase):

def setUp(self):
Expand All @@ -23,6 +21,7 @@ def setUp(self):
with suppress(OSError):
os.remove('{}.md5'.format(self.testfilepath))

@network
def test_download_from_github(self):
ds = tutorial.load_dataset(self.testfile)
tiny = DataArray(range(5), name='tiny').to_dataset()
Expand Down