Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions sklearn/datasets/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -1216,7 +1215,7 @@ def load_sample_images():
descr = load_descr("README.txt", descr_module=IMAGES_MODULE)

filenames, images = [], []
for filename in sorted(resources.contents(IMAGES_MODULE)):
for filename in sorted(_contents(IMAGES_MODULE)):
if filename.endswith(".jpg"):
filenames.append(filename)
with _open_binary(IMAGES_MODULE, filename) as image_file:
Expand Down
11 changes: 11 additions & 0 deletions sklearn/utils/fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)