Skip to content

Commit 138bf89

Browse files
committed
ZipFile context manager is only available in Python >= 2.7
1 parent 8897c6d commit 138bf89

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

sklearn/datasets/california_housing.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,16 @@ def fetch_california_housing(data_home=None, download_if_missing=True):
6363
data_home)
6464
fhandle = urllib2.urlopen(DATA_URL)
6565
buf = StringIO(fhandle.read())
66-
with ZipFile(buf) as zip_file:
66+
zip_file = ZipFile(buf)
67+
try:
6768
cadata_fd = zip_file.open('cadata.txt', 'r')
6869
cadata = StringIO(cadata_fd.read())
6970
# skip the first 27 lines (documentation)
7071
cal_housing = np.loadtxt(cadata, skiprows=27)
7172
joblib.dump(cal_housing, join(data_home, TARGET_FILENAME),
7273
compress=6)
74+
finally:
75+
zip_file.close()
7376
else:
7477
cal_housing = joblib.load(join(data_home, TARGET_FILENAME))
7578

0 commit comments

Comments
 (0)