Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions xarray/backends/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,25 @@ def maybe_decode_store(store, lock=False):
store = filename_or_obj
elif isinstance(filename_or_obj, basestring):
if filename_or_obj.endswith('.gz'):
if engine is not None and engine != 'scipy':
raise ValueError('can only read gzipped netCDF files with '
"default engine or engine='scipy'")
# if the string ends with .gz, then gunzip and open as netcdf file
if is_remote_uri(filename_or_obj):
if engine !='netcdf4' and engine !='pydap':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pep8 nit: you're missing a space after !=.

raise ValueError('can only read remote gzipped netCDF files '
"with engine='netcdf4' or 'pydap'")
else:
if engine is not None and engine != 'scipy':
raise ValueError('can only read gzipped netCDF files with '
"default engine, engine='scipy'")
# if the string ends with .gz, then gunzip and open as netcdf file
if sys.version_info[:2] < (2, 7):
raise ValueError('reading a gzipped netCDF not '
'supported on Python 2.6')
try:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This try/except clause needs to only wrap the call to ScipyDataStore -- otherwise it's catching too many potentially wrong conditions.

store = backends.ScipyDataStore(gzip.open(filename_or_obj))
if engine == 'netcdf4':
store = backends.NetCDF4DataStore(filename_or_obj, group=group)
elif engine == 'pydap':
store = backends.PydapDataStore(filename_or_obj)
else:
store = backends.ScipyDataStore(gzip.open(filename_or_obj))
except TypeError as e:
# TODO: gzipped loading only works with NetCDF3 files.
if 'is not a valid NetCDF 3 file' in e.message:
Expand Down