Skip to content

Commit

Permalink
Reading gzip files in Python 2.6 not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
Valliappa Lakshmanan committed Sep 23, 2014
1 parent 4b8d0d6 commit 4718c48
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions xray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import functools
from io import BytesIO
import warnings
import sys

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -64,6 +65,8 @@ def open_dataset(nc, decode_cf=True, mask_and_scale=True, decode_times=True,
if nc.endswith('.gz'):
# the name ends with .gz, then gunzip and open as netcdf file
# FIXME: does ScipyDataStore handle NetCDF4 files?
if sys.version_info[:2] < (2, 7):
raise ValueError('reading a gzipped netCDF not supported on Python 2.6')
store = backends.ScipyDataStore(gzip.open(nc), *args, **kwargs)
elif not nc.startswith('CDF'):
# it does not appear to be the contents of a netcdf file we load
Expand Down
11 changes: 8 additions & 3 deletions xray/test/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os.path
import tempfile
import unittest
import sys

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -175,9 +176,13 @@ def test_roundtrip_example_1_netcdf(self):
self.assertDatasetIdentical(expected, actual)

def test_roundtrip_example_1_netcdf_gz(self):
with open_example_dataset('example_1.nc.gz') as expected:
with open_example_dataset('example_1.nc') as actual:
self.assertDatasetIdentical(expected, actual)
if sys.version_info[:2] < (2, 7):
with self.assertRaisesRegexp(ValueError, 'gzipped netCDF not supported'):
open_example_dataset('example_1.nc.gz')
else:
with open_example_dataset('example_1.nc.gz') as expected:
with open_example_dataset('example_1.nc') as actual:
self.assertDatasetIdentical(expected, actual)

def test_orthogonal_indexing(self):
in_memory = create_test_data()
Expand Down

0 comments on commit 4718c48

Please sign in to comment.