From c968ea22fd1a0ef73b3aae42debcbcc5c6a998f2 Mon Sep 17 00:00:00 2001 From: Luciano Curto Pelle Date: Fri, 22 Sep 2017 19:38:37 +0100 Subject: [PATCH] Update california_housing.py issue #9820 --- sklearn/datasets/california_housing.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sklearn/datasets/california_housing.py b/sklearn/datasets/california_housing.py index 15a8a2ec603b3..c90ff29ff64f6 100644 --- a/sklearn/datasets/california_housing.py +++ b/sklearn/datasets/california_housing.py @@ -98,13 +98,19 @@ def fetch_california_housing(data_home=None, download_if_missing=True): ARCHIVE.url, data_home)) archive_path = _fetch_remote(ARCHIVE, dirname=data_home) - fileobj = tarfile.open( + tarobj = tarfile.open( mode="r:gz", - name=archive_path).extractfile( + name=archive_path) + fileobj = tarobj.extractfile( 'CaliforniaHousing/cal_housing.data') - remove(archive_path) cal_housing = np.loadtxt(fileobj, delimiter=',') + + # Delete archive file + fileobj.close() + tarobj.close() + remove(archive_path) + # Columns are not in the same order compared to the previous # URL resource on lib.stat.cmu.edu columns_index = [8, 7, 2, 3, 4, 5, 6, 1, 0]