Skip to content

Commit 767bea9

Browse files
author
Hamzeh Alsalhi
committed
Fomate pep8 and remove redundant test for 'new_labels' error
1 parent 39bd9e8 commit 767bea9

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

sklearn/preprocessing/label.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import array
1313
import warnings
1414

15-
import operator
1615
import numpy as np
1716
import scipy.sparse as sp
1817

@@ -108,9 +107,11 @@ class LabelEncoder(BaseEstimator, TransformerMixin):
108107

109108
def __init__(self, new_labels="raise"):
110109
# Check new_labels parameter
111-
if new_labels not in ["update", "raise"] and type(new_labels) is not int:
112-
raise ValueError("Value of argument `new_labels`={0} is unknown "
113-
"and not an integer.".format(new_labels))
110+
if (new_labels not in ["update", "raise"] and
111+
type(new_labels) is not int):
112+
raise ValueError("Value of argument `new_labels`={0} is "
113+
"unknown and not an "
114+
"integer.".format(new_labels))
114115
self.new_labels = new_labels
115116

116117
def _check_fitted(self):
@@ -505,7 +506,8 @@ def label_binarize(y, classes, neg_label=0, pos_label=1,
505506
allow for fitting to classes independently of the transform operation
506507
"""
507508
if not isinstance(y, list):
508-
# XXX Workaround that will be removed when list of list format is dropped
509+
# XXX Workaround that will be removed when list of list format is
510+
# dropped
509511
y = check_array(y, accept_sparse='csr', ensure_2d=False)
510512
if neg_label >= pos_label:
511513
raise ValueError("neg_label={0} must be strictly less than "

sklearn/preprocessing/tests/test_label.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,6 @@ def test_label_encoder_new_label_replace():
240240
assert_array_equal(le.inverse_transform([3, 1, 0]), ["d", "b", "a"])
241241

242242

243-
def test_label_encoder_new_label_arg():
244-
"""Test LabelEncoder's new_labels argument handling"""
245-
assert_raises(ValueError, LabelEncoder, "xyz")
246-
247-
248243
def test_label_encoder_fit_transform():
249244
"""Test fit_transform"""
250245
le = LabelEncoder()
@@ -261,7 +256,7 @@ def test_label_encoder_errors():
261256
le = LabelEncoder()
262257
assert_raises(ValueError, le.transform, [])
263258
assert_raises(ValueError, le.inverse_transform, [])
264-
# Fail on unrecognized vlaue for the 'new_label' parameter
259+
# Fail on unrecognized vlaue for the 'new_label' parameter
265260
assert_raises(ValueError, LabelEncoder, "xyz")
266261

267262

0 commit comments

Comments
 (0)