From 1699e2066b7b9c8f81632050f8570bebe7a506c9 Mon Sep 17 00:00:00 2001 From: Guillaume Lemaitre Date: Thu, 23 Mar 2023 10:32:56 +0100 Subject: [PATCH 1/4] MAINT remove deprecated call to resources.content --- sklearn/datasets/_base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sklearn/datasets/_base.py b/sklearn/datasets/_base.py index 902deae119c48..8dd0fada5e81d 100644 --- a/sklearn/datasets/_base.py +++ b/sklearn/datasets/_base.py @@ -1216,7 +1216,8 @@ def load_sample_images(): descr = load_descr("README.txt", descr_module=IMAGES_MODULE) filenames, images = [], [] - for filename in sorted(resources.contents(IMAGES_MODULE)): + content = [path.name for path in resources.files(IMAGES_MODULE).iterdir()] + for filename in sorted(content): if filename.endswith(".jpg"): filenames.append(filename) with _open_binary(IMAGES_MODULE, filename) as image_file: From aecee2532e87dd82f301381cc34650a11e4df72f Mon Sep 17 00:00:00 2001 From: Guillaume Lemaitre Date: Thu, 23 Mar 2023 10:34:54 +0100 Subject: [PATCH 2/4] [scipy-dev] [azure parallel] trigger SciPy dev From e528cc2db487ae6722a5908f35df8cd91ddf357a Mon Sep 17 00:00:00 2001 From: Guillaume Lemaitre Date: Thu, 23 Mar 2023 11:10:35 +0100 Subject: [PATCH 3/4] using dynamic resources --- sklearn/datasets/_base.py | 6 ++---- sklearn/utils/fixes.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/sklearn/datasets/_base.py b/sklearn/datasets/_base.py index 8dd0fada5e81d..6331582cffb4a 100644 --- a/sklearn/datasets/_base.py +++ b/sklearn/datasets/_base.py @@ -14,14 +14,13 @@ import os from os import environ, listdir, makedirs from os.path import expanduser, isdir, join, splitext -from importlib import resources from pathlib import Path from ..preprocessing import scale from ..utils import Bunch from ..utils import check_random_state from ..utils import check_pandas_support -from ..utils.fixes import _open_binary, _open_text, _read_text +from ..utils.fixes import _open_binary, _open_text, _read_text, _contents import numpy as np @@ -1216,8 +1215,7 @@ def load_sample_images(): descr = load_descr("README.txt", descr_module=IMAGES_MODULE) filenames, images = [], [] - content = [path.name for path in resources.files(IMAGES_MODULE).iterdir()] - for filename in sorted(content): + for filename in sorted(_contents(IMAGES_MODULE)): if filename.endswith(".jpg"): filenames.append(filename) with _open_binary(IMAGES_MODULE, filename) as image_file: diff --git a/sklearn/utils/fixes.py b/sklearn/utils/fixes.py index 587a03fadc76d..d3eaf0540d7ab 100644 --- a/sklearn/utils/fixes.py +++ b/sklearn/utils/fixes.py @@ -215,3 +215,14 @@ def _is_resource(data_module, data_file_name): return resources.files(data_module).joinpath(data_file_name).is_file() else: return resources.is_resource(data_module, data_file_name) + + +def _contents(data_module): + if sys.version_info >= (3, 9): + return ( + resource.name + for resource in resources.files(data_module).iterdir() + if resource.is_file() + ) + else: + return resources.contents(data_module) From f0d003bd585e73627a974ba2951da3f35ec8e602 Mon Sep 17 00:00:00 2001 From: Guillaume Lemaitre Date: Thu, 23 Mar 2023 11:10:42 +0100 Subject: [PATCH 4/4] [scipy-dev] [azure parallel] trigger SciPy dev