Skip to content

Commit

Permalink
Add test_coarsen_keep_attrs to xarray/tests/test_variable.py for issue
Browse files Browse the repository at this point in the history
  • Loading branch information
amcnicho committed Feb 26, 2020
1 parent b14eea2 commit 12da492
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions xarray/tests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -1677,6 +1677,30 @@ def test_binary_ops_keep_attrs(self):
d = a - b
assert d.attrs == _attrs

def test_coarsen_keep_attrs(self):
_attrs = {"units": "test", "long_name": "testing"}

var1 = np.linspace(10, 15, 100)
var2 = np.linspace(5, 10, 100)
coords = np.linspace(1, 10, 100)

ds = xr.Dataset(
data_vars={'var1': ('coord', var1),
'var2': ('coord', var2)},
coords={'coord': coords}
)
ds.attrs['units'] = 'test'
ds.attrs['long_name'] = 'testing'

# Test dropped attrs
dat = ds.coarsen(coord=5).mean()
assert dat.attrs == {}

# Test kept attrs
with set_options(keep_attrs=True):
dat = ds.coarsen(coord=5).mean()
assert dat.attrs == _attrs

def test_count(self):
expected = Variable([], 3)
actual = Variable(["x"], [1, 2, 3, np.nan]).count()
Expand Down

0 comments on commit 12da492

Please sign in to comment.