Skip to content

Commit 952ef66

Browse files
amuellerrth
authored andcommitted
MRG Drop legacy python / remove six dependencies (#12639)
1 parent 51eb2a7 commit 952ef66

File tree

139 files changed

+335
-551
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+335
-551
lines changed

benchmarks/bench_plot_fastkmeans.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ def compute_bench_2(chunks):
104104
results = compute_bench(samples_range, features_range)
105105
results_2 = compute_bench_2(chunks)
106106

107-
max_time = max([max(i) for i in [t for (label, t) in six.iteritems(results)
107+
max_time = max([max(i) for i in [t for (label, t) in results.items()
108108
if "speed" in label]])
109109
max_inertia = max([max(i) for i in [
110-
t for (label, t) in six.iteritems(results)
110+
t for (label, t) in results.items()
111111
if "speed" not in label]])
112112

113113
fig = plt.figure('scikit-learn K-Means benchmark results')
114114
for c, (label, timings) in zip('brcy',
115-
sorted(six.iteritems(results))):
115+
sorted(results.items())):
116116
if 'speed' in label:
117117
ax = fig.add_subplot(2, 2, 1, projection='3d')
118118
ax.set_zlim3d(0.0, max_time * 1.1)
@@ -129,7 +129,7 @@ def compute_bench_2(chunks):
129129

130130
i = 0
131131
for c, (label, timings) in zip('br',
132-
sorted(six.iteritems(results_2))):
132+
sorted(results_2.items())):
133133
i += 1
134134
ax = fig.add_subplot(2, 2, i + 2)
135135
y = np.asarray(timings)

benchmarks/bench_plot_omp_lars.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def compute_bench(samples_range, features_range):
109109

110110
import matplotlib.pyplot as plt
111111
fig = plt.figure('scikit-learn OMP vs. LARS benchmark results')
112-
for i, (label, timings) in enumerate(sorted(six.iteritems(results))):
112+
for i, (label, timings) in enumerate(sorted(results.items())):
113113
ax = fig.add_subplot(1, 2, i+1)
114114
vmax = max(1 - timings.min(), -1 + timings.max())
115115
plt.matshow(timings, fignum=False, vmin=1 - vmax, vmax=1 + vmax)

benchmarks/bench_plot_svd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def compute_bench(samples_range, features_range, n_iter=3, rank=50):
6666
label = 'scikit-learn singular value decomposition benchmark results'
6767
fig = plt.figure(label)
6868
ax = fig.gca(projection='3d')
69-
for c, (label, timings) in zip('rbg', sorted(six.iteritems(results))):
69+
for c, (label, timings) in zip('rbg', sorted(results.items())):
7070
X, Y = np.meshgrid(samples_range, features_range)
7171
Z = np.asarray(timings).reshape(samples_range.shape[0],
7272
features_range.shape[0])

benchmarks/bench_random_projections.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import scipy.sparse as sp
2020

2121
from sklearn import clone
22-
from sklearn.externals.six.moves import xrange
2322
from sklearn.random_projection import (SparseRandomProjection,
2423
GaussianRandomProjection,
2524
johnson_lindenstrauss_min_dim)
@@ -212,7 +211,7 @@ def print_row(clf_type, time_fit, time_transform):
212211
for name in selected_transformers:
213212
print("Perform benchmarks for %s..." % name)
214213

215-
for iteration in xrange(opts.n_times):
214+
for iteration in range(opts.n_times):
216215
print("\titer %s..." % iteration, end="")
217216
time_to_fit, time_to_transform = bench_scikit_transformer(X_dense,
218217
transformers[name])

benchmarks/bench_sample_without_replacement.py

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import numpy as np
1616
import random
1717

18-
from sklearn.externals.six.moves import xrange
1918
from sklearn.utils.random import sample_without_replacement
2019

2120

@@ -90,49 +89,47 @@ def bench_sample(sampling, n_population, n_samples):
9089
# Set Python core input
9190
sampling_algorithm["python-core-sample"] = \
9291
lambda n_population, n_sample: \
93-
random.sample(xrange(n_population), n_sample)
92+
random.sample(range(n_population), n_sample)
9493

95-
###########################################################################
94+
###########################################################################
9695
# Set custom automatic method selection
9796
sampling_algorithm["custom-auto"] = \
9897
lambda n_population, n_samples, random_state=None: \
99-
sample_without_replacement(n_population,
100-
n_samples,
101-
method="auto",
102-
random_state=random_state)
98+
sample_without_replacement(n_population, n_samples, method="auto",
99+
random_state=random_state)
103100

104101
###########################################################################
105102
# Set custom tracking based method
106103
sampling_algorithm["custom-tracking-selection"] = \
107104
lambda n_population, n_samples, random_state=None: \
108-
sample_without_replacement(n_population,
109-
n_samples,
110-
method="tracking_selection",
111-
random_state=random_state)
105+
sample_without_replacement(n_population,
106+
n_samples,
107+
method="tracking_selection",
108+
random_state=random_state)
112109

113110
###########################################################################
114111
# Set custom reservoir based method
115112
sampling_algorithm["custom-reservoir-sampling"] = \
116113
lambda n_population, n_samples, random_state=None: \
117-
sample_without_replacement(n_population,
118-
n_samples,
119-
method="reservoir_sampling",
120-
random_state=random_state)
114+
sample_without_replacement(n_population,
115+
n_samples,
116+
method="reservoir_sampling",
117+
random_state=random_state)
121118

122119
###########################################################################
123120
# Set custom reservoir based method
124121
sampling_algorithm["custom-pool"] = \
125122
lambda n_population, n_samples, random_state=None: \
126-
sample_without_replacement(n_population,
127-
n_samples,
128-
method="pool",
129-
random_state=random_state)
123+
sample_without_replacement(n_population,
124+
n_samples,
125+
method="pool",
126+
random_state=random_state)
130127

131128
###########################################################################
132129
# Numpy permutation based
133130
sampling_algorithm["numpy-permutation"] = \
134131
lambda n_population, n_sample: \
135-
np.random.permutation(n_population)[:n_sample]
132+
np.random.permutation(n_population)[:n_sample]
136133

137134
###########################################################################
138135
# Remove unspecified algorithm
@@ -156,11 +153,11 @@ def bench_sample(sampling, n_population, n_samples):
156153
print("Perform benchmarks for %s..." % name, end="")
157154
time[name] = np.zeros(shape=(opts.n_steps, opts.n_times))
158155

159-
for step in xrange(opts.n_steps):
160-
for it in xrange(opts.n_times):
156+
for step in range(opts.n_steps):
157+
for it in range(opts.n_times):
161158
time[name][step, it] = bench_sample(sampling_algorithm[name],
162-
opts.n_population,
163-
n_samples[step])
159+
opts.n_population,
160+
n_samples[step])
164161

165162
print("done")
166163

doc/conf.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from __future__ import print_function
1616
import sys
1717
import os
18-
from sklearn.externals.six import u
1918

2019
# If extensions (or modules to document with autodoc) are in another
2120
# directory, add these directories to sys.path here. If the directory
@@ -74,8 +73,8 @@
7473
master_doc = 'index'
7574

7675
# General information about the project.
77-
project = u('scikit-learn')
78-
copyright = u('2007 - 2018, scikit-learn developers (BSD License)')
76+
project = 'scikit-learn'
77+
copyright = '2007 - 2018, scikit-learn developers (BSD License)'
7978

8079
# The version info for the project you're documenting, acts as replacement for
8180
# |version| and |release|, also used in various other places throughout the
@@ -214,8 +213,8 @@
214213
# Grouping the document tree into LaTeX files. List of tuples
215214
# (source start file, target name, title, author, documentclass
216215
# [howto/manual]).
217-
latex_documents = [('index', 'user_guide.tex', u('scikit-learn user guide'),
218-
u('scikit-learn developers'), 'manual'), ]
216+
latex_documents = [('index', 'user_guide.tex', 'scikit-learn user guide',
217+
'scikit-learn developers', 'manual'), ]
219218

220219
# The name of an image file (relative to this directory) to place at the top of
221220
# the title page.

doc/developers/contributing.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -907,9 +907,7 @@ in the examples.
907907
Python versions supported
908908
-------------------------
909909

910-
All scikit-learn code should work unchanged in Python 3.5 or
911-
newer.
912-
910+
Since scikit-learn 0.21, only Python 3.5 and newer is supported.
913911

914912
.. _code_review:
915913

doc/developers/performance.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,13 @@ Now restart IPython and let us use this new toy::
227227
178 # values justified in the paper
228228
179 48 144 3.0 0.0 alpha = 1
229229
180 48 113 2.4 0.0 beta = 0.1
230-
181 638 1880 2.9 0.1 for n_iter in xrange(1, max_iter + 1):
230+
181 638 1880 2.9 0.1 for n_iter in range(1, max_iter + 1):
231231
182 638 195133 305.9 10.2 grad = np.dot(WtW, H) - WtV
232232
183 638 495761 777.1 25.9 proj_gradient = norm(grad[np.logical_or(grad < 0, H > 0)])
233233
184 638 2449 3.8 0.1 if proj_gradient < tol:
234234
185 48 130 2.7 0.0 break
235235
186
236-
187 1474 4474 3.0 0.2 for inner_iter in xrange(1, 20):
236+
187 1474 4474 3.0 0.2 for inner_iter in range(1, 20):
237237
188 1474 83833 56.9 4.4 Hn = H - alpha * grad
238238
189 # Hn = np.where(Hn > 0, Hn, 0)
239239
190 1474 194239 131.8 10.1 Hn = _pos(Hn)

examples/applications/plot_out_of_core_classification.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
import matplotlib.pyplot as plt
4141
from matplotlib import rcParams
4242

43-
from sklearn.externals.six.moves import html_parser
44-
from sklearn.externals.six.moves.urllib.request import urlretrieve
43+
from html.parser import HTMLParser
44+
from urllib.request import urlretrieve
4545
from sklearn.datasets import get_data_home
4646
from sklearn.feature_extraction.text import HashingVectorizer
4747
from sklearn.linear_model import SGDClassifier
@@ -60,11 +60,11 @@ def _not_in_sphinx():
6060
#
6161

6262

63-
class ReutersParser(html_parser.HTMLParser):
63+
class ReutersParser(HTMLParser):
6464
"""Utility class to parse a SGML file and yield documents one at a time."""
6565

6666
def __init__(self, encoding='latin-1'):
67-
html_parser.HTMLParser.__init__(self)
67+
HTMLParser.__init__(self)
6868
self._reset()
6969
self.encoding = encoding
7070

examples/applications/svm_gui.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939

4040
from sklearn import svm
4141
from sklearn.datasets import dump_svmlight_file
42-
from sklearn.externals.six.moves import xrange
4342

4443
y_min, y_max = -50, 50
4544
x_min, x_max = -50, 50
@@ -187,7 +186,7 @@ def update_example(self, model, idx):
187186

188187
def update(self, event, model):
189188
if event == "examples_loaded":
190-
for i in xrange(len(model.data)):
189+
for i in range(len(model.data)):
191190
self.update_example(model, i)
192191

193192
if event == "example_added":

0 commit comments

Comments
 (0)