Skip to content

Commit eb40a5f

Browse files
authored
MNT Clean-up deprecations for 1.7: byte labels (scikit-learn#31236)
1 parent ec74b2a commit eb40a5f

File tree

3 files changed

+9
-23
lines changed

3 files changed

+9
-23
lines changed

sklearn/metrics/tests/test_ranking.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -873,20 +873,15 @@ def test_binary_clf_curve_implicit_pos_label(curve_func):
873873
np.testing.assert_allclose(int_curve_part, float_curve_part)
874874

875875

876-
# TODO(1.7): Update test to check for error when bytes support is removed.
877876
@pytest.mark.filterwarnings("ignore:Support for labels represented as bytes")
878877
@pytest.mark.parametrize("curve_func", [precision_recall_curve, roc_curve])
879878
@pytest.mark.parametrize("labels_type", ["list", "array"])
880879
def test_binary_clf_curve_implicit_bytes_pos_label(curve_func, labels_type):
881880
# Check that using bytes class labels raises an informative
882881
# error for any supported string dtype:
883882
labels = _convert_container([b"a", b"b"], labels_type)
884-
msg = (
885-
"y_true takes value in {b'a', b'b'} and pos_label is not "
886-
"specified: either make y_true take value in {0, 1} or "
887-
"{-1, 1} or pass pos_label explicitly."
888-
)
889-
with pytest.raises(ValueError, match=msg):
883+
msg = "Support for labels represented as bytes is not supported"
884+
with pytest.raises(TypeError, match=msg):
890885
curve_func(labels, [0.0, 1.0])
891886

892887

sklearn/utils/multiclass.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -358,17 +358,12 @@ def _raise_or_return():
358358
y = check_array(y, dtype=object, **check_y_kwargs)
359359

360360
try:
361-
# TODO(1.7): Change to ValueError when byte labels is deprecated.
362-
# labels in bytes format
363361
first_row_or_val = y[[0], :] if issparse(y) else y[0]
362+
# labels in bytes format
364363
if isinstance(first_row_or_val, bytes):
365-
warnings.warn(
366-
(
367-
"Support for labels represented as bytes is deprecated in v1.5 and"
368-
" will error in v1.7. Convert the labels to a string or integer"
369-
" format."
370-
),
371-
FutureWarning,
364+
raise TypeError(
365+
"Support for labels represented as bytes is not supported. Convert "
366+
"the labels to a string or integer format."
372367
)
373368
# The old sequence of sequences format
374369
if (

sklearn/utils/tests/test_multiclass.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -602,16 +602,12 @@ def test_ovr_decision_function():
602602
assert_allclose(dec_values, dec_values_one, atol=1e-6)
603603

604604

605-
# TODO(1.7): Change to ValueError when byte labels is deprecated.
606605
@pytest.mark.parametrize("input_type", ["list", "array"])
607-
def test_labels_in_bytes_format(input_type):
606+
def test_labels_in_bytes_format_error(input_type):
608607
# check that we raise an error with bytes encoded labels
609608
# non-regression test for:
610609
# https://github.com/scikit-learn/scikit-learn/issues/16980
611610
target = _convert_container([b"a", b"b"], input_type)
612-
err_msg = (
613-
"Support for labels represented as bytes is deprecated in v1.5 and will"
614-
" error in v1.7. Convert the labels to a string or integer format."
615-
)
616-
with pytest.warns(FutureWarning, match=err_msg):
611+
err_msg = "Support for labels represented as bytes is not supported"
612+
with pytest.raises(TypeError, match=err_msg):
617613
type_of_target(target)

0 commit comments

Comments
 (0)