8000 MAINT remove deprecated call to resources.content by glemaitre · Pull Request #25951 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

MAINT remove deprecated call to resources.content #25951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 23, 2023
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
< 8000 /div>
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)
0