10000 Merge pull request #1812 from kmike/testing-fixes · nullnotfound/scikit-learn@6d47ec0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6d47ec0

Browse files
committed
Merge pull request scikit-learn#1812 from kmike/testing-fixes
Some Python 3.x-related testing fixes
2 parents bf0c1a3 + 2af2c73 commit 6d47ec0

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

sklearn/preprocessing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,8 +672,8 @@ class OneHotEncoder(BaseEstimator, TransformerMixin):
672672
673673
>>> from sklearn.preprocessing import OneHotEncoder
674674
>>> enc = OneHotEncoder()
675-
>>> enc.fit([[0, 0, 3], [1, 1, 0], [0, 2, 1], [1, 0, 2]])
676-
OneHotEncoder(dtype=<type 'float'>, n_values='auto')
675+
>>> enc.fit([[0, 0, 3], [1, 1, 0], [0, 2, 1], [1, 0, 2]]) # doctest: +ELLIPSIS
676+
OneHotEncoder(dtype=<... 'float'>, n_values='auto')
677677
>>> enc.n_values_
678678
array([2, 3, 4])
679679
>>> enc.feature_indices_

sklearn/tests/test_common.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,13 @@ def test_estimators_sparse_data():
130130
# fit
131131
try:
132132
classifier.fit(X, y)
133-
except TypeError, e:
133+
except TypeError as e:
134134
if not 'sparse' in repr(e):
135135
print("Estimator %s doesn't seem to fail gracefully on "
136136
"sparse data" % name)
137137
traceback.print_exc(file=sys.stdout)
138138
raise e
139-
except Exception, exc:
139+
except Exception as exc:
140140
print("Estimator %s doesn't seem to fail gracefully on "
141141
"sparse data" % name)
142142
traceback.print_exc(file=sys.stdout)
@@ -263,13 +263,13 @@ def test_transformers_sparse_data():
263263
# fit
264264
try:
265265
transformer.fit(X, y)
266-
except TypeError, e:
266+
except TypeError as e:
267267
if not 'sparse' in repr(e):
268268
print("Estimator %s doesn't seem to fail gracefully on "
269269
"sparse data" % name)
270270
traceback.print_exc(file=sys.stdout)
271271
raise e
272-
except Exception, exc:
272+
except Exception as exc:
273273
print("Estimator %s doesn't seem to fail gracefully on "
274274
"sparse data" % name)
275275
traceback.print_exc(file=sys.stdout)
@@ -324,12 +324,12 @@ def test_estimators_nan_inf():
324324
estimator.fit(X_train)
325325
else:
326326
estimator.fit(X_train, y)
327-
except ValueError, e:
327+
except ValueError as e:
328328
if not 'inf' in repr(e) and not 'NaN' in repr(e):
329329
print(error_string_fit, Estimator, e)
330330
traceback.print_exc(file=sys.stdout)
331331
raise e
332-
except Exception, exc:
332+
except Exception as exc:
333333
print(error_string_fit, Estimator, exc)
334334
traceback.print_exc(file=sys.stdout)
335335
raise exc
@@ -347,12 +347,12 @@ def test_estimators_nan_inf():
347347
if hasattr(estimator, "predict"):
348348
try:
349349
estimator.predict(X_train)
350-
except ValueError, e:
350+
except ValueError as e:
351351
if not 'inf' in repr(e) and not 'NaN' in repr(e):
352352
print(error_string_predict, Estimator, e)
353353
traceback.print_exc(file=sys.stdout)
354354
raise e
355-
except Exception, exc:
355+
except Exception as exc:
356356
print(error_string_predict, Estimator, exc)
357357
traceback.print_exc(file=sys.stdout)
358358
else:
@@ -362,12 +362,12 @@ def test_estimators_nan_inf():
362362
if hasattr(estimator, "transform"):
363363
try:
364364
estimator.transform(X_train)
365-
except ValueError, e:
365+
except ValueError as e:
366366
if not 'inf' in repr(e) and not 'NaN' in repr(e):
367367
print(error_string_transform, Estimator, e)
368368
traceback.print_exc(file=sys.stdout)
369369
raise e
370-
except Exception, exc:
370+
except Exception as exc:
371371
print(error_string_transform, Estimator, exc)
372372
traceback.print_exc(file=sys.stdout)
373373
else:
@@ -425,7 +425,7 @@ def test_transformers_pickle():
425425

426426
try:
427427
assert_array_almost_equal(pickled_X_pred, X_pred)
428-
except Exception, exc:
428+
except Exception as exc:
429429
succeeded = False
430430
print ("Transformer %s doesn't predict the same value "
431431
"after pickling" % name)
@@ -454,21 +454,21 @@ def test_classifiers_one_label():
454454
# try to fit
455455
try:
456456
classifier.fit(X_train, y)
457-
except ValueError, e:
457+
except ValueError as e:
458458
if not 'class' in repr(e):
459459
print(error_string_fit, Classifier, e)
460460
traceback.print_exc(file=sys.stdout)
461461
raise e
462462
else:
463463
continue
464-
except Exception, exc:
464+
except Exception as exc:
465465
print(error_string_fit, Classifier, exc)
466466
traceback.print_exc(file=sys.stdout)
467467
raise exc
468468
# predict
469469
try:
470470
assert_array_equal(classifier.predict(X_test), y)
471-
except Exception, exc:
471+
except Exception as exc:
472472
print(error_string_predict, Classifier, exc)
473473
traceback.print_exc(file=sys.stdout)
474474

@@ -671,7 +671,7 @@ def test_classifiers_pickle():
671671

672672
try:
673673
assert_array_almost_equal(pickled_y_pred, y_pred)
674-
except Exception, exc:
674+
except Exception as exc:
675675
succeeded = False
676676
print ("Estimator %s doesn't predict the same value "
677677
"after pickling" % name)
@@ -802,7 +802,7 @@ def test_regressor_pickle():
802802

803803
try:
804804
assert_array_almost_equal(pickled_y_pred, y_pred)
805-
except Exception, exc:
805+
except Exception as exc:
806806
succeeded = False
807807
print ("Estimator %s doesn't predict the same value "
808808
"after pickling" % name)

sklearn/tests/test_cross_validation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,10 @@ def test_stratified_shuffle_split_iter_no_indices():
231231
y = np.asarray([0, 1, 2] * 10)
232232

233233
sss1 = cval.StratifiedShuffleSplit(y, indices=False, random_state=0)
234-
train_mask, test_mask = iter(sss1).next()
234+
train_mask, test_mask = next(iter(sss1))
235235

236236
sss2 = cval.StratifiedShuffleSplit(y, indices=True, random_state=0)
237-
train_indices, test_indices = iter(sss2).next()
237+
train_indices, test_indices = next(iter(sss2))
238238

239239
assert_array_equal(sorted(test_indices), np.where(test_mask)[0])
240240

@@ -482,7 +482,7 @@ def test_cross_val_generator_mask_indices_same():
482482
# indices=True and when indices=False
483483
y = np.array([0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2])
484484
labels = np.array([1, 1, 2, 3, 3, 3, 4])
485-
485+
486486
loo_mask = cval.LeaveOneOut(5, indices=False)
487487
loo_ind = cval.LeaveOneOut(5, indices=True)
488488
lpo_mask = cval.LeavePOut(10, 2, indices=False)
@@ -495,7 +495,7 @@ def test_cross_val_generator_mask_indices_same():
495495
lolo_ind = cval.LeaveOneLabelOut(labels, indices=True)
496496
lopo_mask = cval.LeavePLabelOut(labels, 2, indices=False)
497497
lopo_ind = cval.LeavePLabelOut(labels, 2, indices=True)
498-
498+
499499
for cv_mask, cv_ind in [(loo_mask, loo_ind), (lpo_mask, lpo_ind),
500500
(kf_mask, kf_ind), (skf_mask, skf_ind), (lolo_mask, lolo_ind),
501501
(lopo_mask, lopo_ind)]:

0 commit comments

Comments
 (0)
0