Skip to content

Commit

Permalink
Tests that attrs retained for open_mfdataset
Browse files Browse the repository at this point in the history
  • Loading branch information
pwolfram committed Mar 24, 2017
1 parent 65555b8 commit 489ded4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions xarray/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,25 @@ def test_open_mfdataset(self):
with self.assertRaisesRegexp(IOError, 'no files to open'):
open_mfdataset('foo-bar-baz-*.nc')

def test_attrs_mfdataset(self):
original = Dataset({'foo': ('x', np.random.randn(10))})
with create_tmp_file() as tmp1:
with create_tmp_file() as tmp2:
ds1 = original.isel(x=slice(5))
ds2 = original.isel(x=slice(5, 10))
ds1.attrs['test1'] = 'foo'
ds2.attrs['test2'] = 'bar'
ds1.to_netcdf(tmp1)
ds2.to_netcdf(tmp2)
with open_mfdataset([tmp1, tmp2]) as actual:
# presumes that attributes inherited from
# first dataset loaded
self.assertEqual(actual.test1, ds1.test1)
# attributes from ds2 are not retained, e.g.,
with self.assertRaisesRegexp(AttributeError,
'no attribute'):
actual.test2

def test_preprocess_mfdataset(self):
original = Dataset({'foo': ('x', np.random.randn(10))})
with create_tmp_file() as tmp:
Expand Down

0 comments on commit 489ded4

Please sign in to comment.