Skip to content

Commit 2c79a98

Browse files
committed
Merge pull request scikit-learn#4431 from vortex-ape/deprecate_func
[MRG + 2] Deprecates load_lfw_pairs and load_lfw_people
2 parents 32b7075 + ce5fada commit 2c79a98

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

doc/modules/classes.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,7 @@ Loaders
210210
datasets.load_digits
211211
datasets.load_files
212212
datasets.load_iris
213-
datasets.load_lfw_pairs
214213
datasets.fetch_lfw_pairs
215-
datasets.load_lfw_people
216214
datasets.fetch_lfw_people
217215
datasets.load_linnerud
218216
datasets.mldata_filename

sklearn/datasets/lfw.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
from os import listdir, makedirs, remove
2727
from os.path import join, exists, isdir
2828

29+
from sklearn.utils import deprecated
30+
2931
import logging
3032
import numpy as np
3133

@@ -362,6 +364,9 @@ def _fetch_lfw_pairs(index_file_path, data_folder_path, slice_=None,
362364
return pairs, target, np.array(['Different persons', 'Same person'])
363365

364366

367+
@deprecated("Function 'load_lfw_people' has been deprecated in 0.17 and will be "
368+
"removed in 0.19."
369+
"Use fetch_lfw_people(download_if_missing=False) instead.")
365370
def load_lfw_people(download_if_missing=False, **kwargs):
366371
"""Alias for fetch_lfw_people(download_if_missing=False)
367372
@@ -484,6 +489,9 @@ def fetch_lfw_pairs(subset='train', data_home=None, funneled=True, resize=0.5,
484489
DESCR="'%s' segment of the LFW pairs dataset" % subset)
485490

486491

492+
@deprecated("Function 'load_lfw_pairs' has been deprecated in 0.17 and will be "
493+
"removed in 0.19."
494+
"Use fetch_lfw_pairs(download_if_missing=False) instead.")
487495
def load_lfw_pairs(download_if_missing=False, **kwargs):
488496
"""Alias for fetch_lfw_pairs(download_if_missing=False)
489497

sklearn/datasets/tests/test_lfw.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@
2424

2525
from sklearn.datasets import load_lfw_pairs
2626
from sklearn.datasets import load_lfw_people
27+
from sklearn.datasets import fetch_lfw_pairs
28+
from sklearn.datasets import fetch_lfw_people
2729

2830
from sklearn.utils.testing import assert_array_equal
2931
from sklearn.utils.testing import assert_equal
32+
from sklearn.utils.testing import assert_warns_message
3033
from sklearn.utils.testing import SkipTest
3134
from sklearn.utils.testing import raises
3235

@@ -112,12 +115,20 @@ def teardown_module():
112115

113116
@raises(IOError)
114117
def test_load_empty_lfw_people():
115-
load_lfw_people(data_home=SCIKIT_LEARN_EMPTY_DATA)
118+
fetch_lfw_people(data_home=SCIKIT_LEARN_EMPTY_DATA, download_if_missing=False)
119+
120+
121+
def test_load_lfw_people_deprecation():
122+
msg = ("Function 'load_lfw_people' has been deprecated in 0.17 and will be "
123+
"removed in 0.19."
124+
"Use fetch_lfw_people(download_if_missing=False) instead.")
125+
assert_warns_message(DeprecationWarning, msg, load_lfw_people,
126+
data_home=SCIKIT_LEARN_DATA)
116127

117128

118129
def test_load_fake_lfw_people():
119-
lfw_people = load_lfw_people(data_home=SCIKIT_LEARN_DATA,
120-
min_faces_per_person=3)
130+
lfw_people = fetch_lfw_people(data_home=SCIKIT_LEARN_DATA,
131+
min_faces_per_person=3, download_if_missing=False)
121132

122133
# The data is croped around the center as a rectangular bounding box
123134
# arounthe the face. Colors are converted to gray levels:
@@ -133,8 +144,8 @@ def test_load_fake_lfw_people():
133144

134145
# It is possible to ask for the original data without any croping or color
135146
# conversion and not limit on the number of picture per person
136-
lfw_people = load_lfw_people(data_home=SCIKIT_LEARN_DATA,
137-
resize=None, slice_=None, color=True)
147+
lfw_people = fetch_lfw_people(data_home=SCIKIT_LEARN_DATA,
148+
resize=None, slice_=None, color=True, download_if_missing=False)
138149
assert_equal(lfw_people.images.shape, (17, 250, 250, 3))
139150

140151
# the ids and class names are the same as previously
@@ -147,16 +158,24 @@ def test_load_fake_lfw_people():
147158

148159
@raises(ValueError)
149160
def test_load_fake_lfw_people_too_restrictive():
150-
load_lfw_people(data_home=SCIKIT_LEARN_DATA, min_faces_per_person=100)
161+
fetch_lfw_people(data_home=SCIKIT_LEARN_DATA, min_faces_per_person=100, download_if_missing=False)
151162

152163

153164
@raises(IOError)
154165
def test_load_empty_lfw_pairs():
155-
load_lfw_pairs(data_home=SCIKIT_LEARN_EMPTY_DATA)
166+
fetch_lfw_pairs(data_home=SCIKIT_LEARN_EMPTY_DATA, download_if_missing=False)
167+
168+
169+
def test_load_lfw_pairs_deprecation():
170+
msg = ("Function 'load_lfw_pairs' has been deprecated in 0.17 and will be "
171+
"removed in 0.19."
172+
"Use fetch_lfw_pairs(download_if_missing=False) instead.")
173+
assert_warns_message(DeprecationWarning, msg, load_lfw_pairs,
174+
data_home=SCIKIT_LEARN_DATA)
156175

157176

158177
def test_load_fake_lfw_pairs():
159-
lfw_pairs_train = load_lfw_pairs(data_home=SCIKIT_LEARN_DATA)
178+
lfw_pairs_train = fetch_lfw_pairs(data_home=SCIKIT_LEARN_DATA, download_if_missing=False)
160179

161180
# The data is croped around the center as a rectangular bounding box
162181
# arounthe the face. Colors are converted to gray levels:
@@ -171,8 +190,8 @@ def test_load_fake_lfw_pairs():
171190

172191
# It is possible to ask for the original data without any croping or color
173192
# conversion
174-
lfw_pairs_train = load_lfw_pairs(data_home=SCIKIT_LEARN_DATA,
175-
resize=None, slice_=None, color=True)
193+
lfw_pairs_train = fetch_lfw_pairs(data_home=SCIKIT_LEARN_DATA,
194+
resize=None, slice_=None, color=True, download_if_missing=False)
176195
assert_equal(lfw_pairs_train.pairs.shape, (10, 2, 250, 250, 3))
177196

178197
# the ids and class names are the same as previously

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy