Skip to content
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

[MRG] Deterministic order for load_sample_images #13250

Merged
merged 13 commits into from Feb 26, 2019
@@ -66,6 +66,9 @@ Support for Python 3.4 and below has been officially dropped.
:class:`datasets.svmlight_format` :issue:`10727` by
:user:`Bryan K Woods <bryan-woods>`.

- |Fix| :func:`datasets.load_sample_images` returns images with a deterministic
order. :issue:`13250` by :user:`Thomas Fan <thomasjpfan>`.

:mod:`sklearn.decomposition`
............................

@@ -794,7 +794,7 @@ def load_sample_images():
with open(join(module_path, 'README.txt')) as f:
descr = f.read()
filenames = [join(module_path, filename)
for filename in os.listdir(module_path)
for filename in sorted(os.listdir(module_path))
if filename.endswith(".jpg")]
# Load image data for each image in the source folder.
images = [imread(filename) for filename in filenames]
@@ -9,6 +9,7 @@

import pytest

import numpy as np
from sklearn.datasets import get_data_home
from sklearn.datasets import clear_data_home
from sklearn.datasets import load_files
@@ -123,6 +124,14 @@ def test_load_sample_images():
res = load_sample_images()
assert_equal(len(res.images), 2)
assert_equal(len(res.filenames), 2)
images = res.images

# assert is china image
assert np.all(images[0][0, 0, :] ==
np.array([174, 201, 231], dtype=np.uint8))
# assert is flower image
assert np.all(images[1][0, 0, :] ==
np.array([2, 19, 13], dtype=np.uint8))
assert res.DESCR
except ImportError:
warnings.warn("Could not load sample images, PIL is not available.")
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.