Skip to content

MAINT cleanup utils.__init__: deprecate tosequence #28763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/whats_new/v1.5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,12 @@ Changelog
given the split condition.
:pr:`28552` by :user:`Adam Li <adam2392>`.

:mod:`sklearn.utils`
....................

- |API| :func:`utils.tosequence` is deprecated and will be removed in version 1.7.
:pr:`28763` by :user:`Jérémie du Boisberranger <jeremiedbb>`.

.. rubric:: Code and documentation contributors

Thanks to everyone who has contributed to the maintenance and improvement of
Expand Down
6 changes: 3 additions & 3 deletions sklearn/ensemble/tests/test_gradient_boosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import scale
from sklearn.svm import NuSVR
from sklearn.utils import check_random_state, tosequence
from sklearn.utils import check_random_state
from sklearn.utils._mocking import NoSampleWeightWrapper
from sklearn.utils._param_validation import InvalidParameterError
from sklearn.utils._testing import (
Expand Down Expand Up @@ -529,10 +529,10 @@ def test_symbol_labels():
# Test with non-integer class labels.
clf = GradientBoostingClassifier(n_estimators=100, random_state=1)

symbol_y = tosequence(map(str, y))
symbol_y = list(map(str, y))

clf.fit(X, symbol_y)
assert_array_equal(clf.predict(T), tosequence(map(str, true_result)))
assert_array_equal(clf.predict(T), list(map(str, true_result)))
assert 100 == len(clf.estimators_)


Expand Down
2 changes: 2 additions & 0 deletions sklearn/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
_IS_WASM = platform.machine() in ["wasm32", "wasm64"]


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

Expand Down
7 changes: 7 additions & 0 deletions sklearn/utils/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
column_or_1d,
deprecated,
safe_mask,
tosequence,
)
from sklearn.utils._missing import is_scalar_nan
from sklearn.utils._testing import assert_array_equal, assert_no_warnings
Expand Down Expand Up @@ -157,3 +158,9 @@ def __init__(self):
self.schema = ["a", "b"]

assert not _is_polars_df(LooksLikePolars())


# TODO(1.7): remove
def test_tosequence_deprecated():
with pytest.warns(FutureWarning, match="tosequence was deprecated in 1.5"):
tosequence([1, 2, 3])