From 4718c484b4efd2c60c51422eb8226d50574d2421 Mon Sep 17 00:00:00 2001 From: Valliappa Lakshmanan Date: Tue, 23 Sep 2014 14:47:10 -0700 Subject: [PATCH] Reading gzip files in Python 2.6 not supported --- xray/core/dataset.py | 3 +++ xray/test/test_backends.py | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/xray/core/dataset.py b/xray/core/dataset.py index ee560c20baa..fcfb194a78e 100644 --- a/xray/core/dataset.py +++ b/xray/core/dataset.py @@ -2,6 +2,7 @@ import functools from io import BytesIO import warnings +import sys import numpy as np import pandas as pd @@ -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 diff --git a/xray/test/test_backends.py b/xray/test/test_backends.py index a0fb6f99d4f..e242ab1a898 100644 --- a/xray/test/test_backends.py +++ b/xray/test/test_backends.py @@ -7,6 +7,7 @@ import os.path import tempfile import unittest +import sys import numpy as np import pandas as pd @@ -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()