8000 MAINT cleanup utils.__init__: deprecate tosequence (#28763) · patrickkwang/scikit-learn@8edbdfc · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit 8edbdfc

Browse files
authored
MAINT cleanup utils.__init__: deprecate tosequence (scikit-learn#28763)
1 parent 941acc4 commit 8edbdfc

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

doc/whats_new/v1.5.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,12 @@ Changelog
332332
given the split condition.
333333
:pr:`28552` by :user:`Adam Li <adam2392>`.
334334
335+
:mod:`sklearn.utils`
336+
....................
337+
338+
- |API| :func:`utils.tosequence` is deprecated and will be removed in version 1.7.
339+
:pr:`28763` by :user:`Jérémie du Boisberranger <jeremiedbb>`.
340+
335341
.. rubric:: Code and documentation contributors
336342
337343
Thanks to everyone who has contributed to the maintenance and improvement of

sklearn/ensemble/tests/test_gradient_boosting.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from sklearn.pipeline import make_pipeline
2323
from sklearn.preprocessing import scale
2424
from sklearn.svm import NuSVR
25-
from sklearn.utils import check_random_state, tosequence
25+
from sklearn.utils import check_random_state
2626
from sklearn.utils._mocking import NoSampleWeightWrapper
2727
from sklearn.utils._param_validation import InvalidParameterError
2828
from sklearn.utils._testing import (
@@ -529,10 +529,10 @@ def test_symbol_labels():
529529
# Test with non-integer class labels.
530530
clf = GradientBoostingClassifier(n_estimators=100, random_state=1)
531531

532-
symbol_y = tosequence(map(str, y))
532+
symbol_y = list(map(str, y))
533533

534534
clf.fit(X, symbol_y)
535-
assert_array_equal(clf.predict(T), tosequence(map(str, true_result)))
535+
assert_array_equal(clf.predict(T), list(map(str, true_result)))
536536
assert 100 == len(clf.estimators_)
537537

538538

sklearn/utils/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@
8686
_IS_WASM = platform.machine() in ["wasm32", "wasm64"]
8787

8888

89+
# TODO(1.7): remove tosequence
90+
@deprecated("tosequence was deprecated in 1.5 and will be removed in 1.7")
8991
def tosequence(x):
9092
"""Cast iterable x to a Sequence, avoiding a copy if possible.
9193

sklearn/utils/tests/test_utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
column_or_1d,
99
deprecated,
1010
safe_mask,
11+
tosequence,
1112
)
1213
from sklearn.utils._missing import is_scalar_nan
1314
from sklearn.utils._testing import assert_array_equal, assert_no_warnings
@@ -157,3 +158,9 @@ def __init__(self):
157158
self.schema = ["a", "b"]
158159

159160
assert not _is_polars_df(LooksLikePolars())
161+
162+
163+
# TODO(1.7): remove
164+
def test_tosequence_deprecated():
165+
with pytest.warns(FutureWarning, match="tosequence was deprecated in 1.5"):
166+
tosequence([1, 2, 3])

0 commit comments

Comments
 (0)
0