Skip to content

Commit

Permalink
attempt to fix #497
Browse files Browse the repository at this point in the history
  • Loading branch information
gidden committed May 21, 2017
1 parent 5f92955 commit a00e156
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 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,21 @@ 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
if 'is not a valid NetCDF 3 file' in e.message:
msg = """
If this is a NetCDF4 file, you may need to install the
netcdf4 library, e.g.,
$ pip install netcdf4
"""
msg = e.message + msg
raise TypeError(msg)
else:
raise


class ScipyDataStore(WritableCFDataStore, DataStorePickleMixin):
Expand All @@ -89,6 +103,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 a00e156

Please sign in to comment.