Skip to content

Commit

Permalink
bug in netcdf time (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmaussion committed Oct 23, 2016
1 parent 0a7c464 commit 151e4af
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
11 changes: 10 additions & 1 deletion docs/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@ What's New
==========


v0.1.0 (22 October 2016)
v0.1.1 (Unreleased)
-------------------

Bug fixes
~~~~~~~~~

- GeoNetCDF files without time variable should now open without error


v0.1.0 (22 October 2016)
------------------------

Big refactoring (:pull:`15`), partly backwards incompatible (mostly renaming).
Improved xarray accessors, WRF tools, merged `Cleo`_ into the codebase,
added a first draft of documentation.
Expand Down
9 changes: 7 additions & 2 deletions salem/sio.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,13 @@ def netcdf_time(ncobj, monthbegin=False):
import pandas as pd

time = None
vt = utils.str_in_list(ncobj.variables.keys(),
utils.valid_names['time_var'])[0]
try:
vt = utils.str_in_list(ncobj.variables.keys(),
utils.valid_names['time_var'])[0]
except IndexError:
# no time variable
return None

if hasattr(ncobj, 'TITLE') and 'GEOGRID' in ncobj.TITLE:
# geogrid file
pass
Expand Down
11 changes: 11 additions & 0 deletions salem/tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ def test_read_to_grid(self):
df2.geometry[0].exterior.coords)


@requires_xarray
def test_notimevar(self):

import xarray as xr
da = xr.DataArray(np.arange(12).reshape(3, 4), dims=['lat', 'lon'])
ds = da.to_dataset('var')

t = sio.netcdf_time(ds)
assert t is None


class TestColors(unittest.TestCase):

@requires_matplotlib
Expand Down

0 comments on commit 151e4af

Please sign in to comment.