Skip to content

Commit

Permalink
fixes #497 by catching scipy netcdf error and adding additional sugge…
Browse files Browse the repository at this point in the history
…stions before rethrowing
  • Loading branch information
gidden committed May 24, 2017
1 parent d802484 commit ae0cbe3
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions xarray/backends/scipy_.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def _decode_attrs(d):


class ScipyArrayWrapper(NdimSizeLenMixin, DunderArrayMixin):

def __init__(self, variable_name, datastore):
self.datastore = datastore
self.variable_name = variable_name
Expand Down Expand Up @@ -77,8 +78,22 @@ def _open_scipy_netcdf(filename, mode, mmap, version):
# it's a NetCDF3 bytestring
filename = BytesIO(filename)

return scipy.io.netcdf_file(filename, mode=mode, mmap=mmap,
version=version)
try:
return scipy.io.netcdf_file(filename, mode=mode, mmap=mmap,
version=version)
except TypeError as e: # netcdf3 message is obscure in this case
errmsg = e.args[0]
if 'is not a valid NetCDF 3 file' in errmsg:
msg = """
If this is a NetCDF4 file, you may need to install the
netcdf4 library, e.g.,
$ pip install netcdf4
"""
errmsg += msg
raise TypeError(errmsg)
else:
raise


class ScipyDataStore(WritableCFDataStore, DataStorePickleMixin):
Expand All @@ -89,6 +104,7 @@ class ScipyDataStore(WritableCFDataStore, DataStorePickleMixin):
It only supports the NetCDF3 file-format.
"""

def __init__(self, filename_or_obj, mode='r', format=None, group=None,
writer=None, mmap=None, autoclose=False):
import scipy
Expand Down

0 comments on commit ae0cbe3

Please sign in to comment.