Skip to content

TST Fix doctests to be compatible with scipy>=1.14 #29385

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

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 4 additions & 0 deletions sklearn/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ def pytest_collection_modifyitems(config, items):
reason = "Due to NEP 51 numpy scalar repr has changed in numpy 2"
skip_doctests = True

if sp_version < parse_version("1.14"):
reason = "Scipy sparse matrix repr has changed in scipy 1.14"
skip_doctests = True

# Normally doctest has the entire module's scope. Here we set globs to an empty dict
# to remove the module's scope:
# https://docs.python.org/3/library/doctest.html#what-s-the-execution-context
Expand Down
3 changes: 3 additions & 0 deletions sklearn/feature_extraction/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ def grid_to_graph(
>>> mask[[1, 2], [1, 2], :] = True
>>> graph = grid_to_graph(*shape_img, mask=mask)
>>> print(graph)
<COOrdinate sparse matrix of dtype 'int64'
with 2 stored elements and shape (2, 2)>
Coords Values
(0, 0) 1
(1, 1) 1
"""
Expand Down
8 changes: 4 additions & 4 deletions sklearn/utils/_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,8 @@ def resample(*arrays, replace=True, n_samples=None, random_state=None, stratify=
[1., 0.]])

>>> X_sparse
<3x2 sparse matrix of type '<... 'numpy.float64'>'
with 4 stored elements in Compressed Sparse Row format>
<Compressed Sparse Row sparse matrix of dtype 'float64'
with 4 stored elements and shape (3, 2)>

>>> X_sparse.toarray()
array([[1., 0.],
Expand Down Expand Up @@ -616,8 +616,8 @@ def shuffle(*arrays, random_state=None, n_samples=None):
[1., 0.]])

>>> X_sparse
<3x2 sparse matrix of type '<... 'numpy.float64'>'
with 3 stored elements in Compressed Sparse Row format>
<Compressed Sparse Row sparse matrix of dtype 'float64'
with 3 stored elements and shape (3, 2)>

>>> X_sparse.toarray()
array([[0., 0.],
Expand Down
6 changes: 3 additions & 3 deletions sklearn/utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ def indexable(*iterables):
... [1, 2, 3], np.array([2, 3, 4]), None, csr_matrix([[5], [6], [7]])
... ]
>>> indexable(*iterables)
[[1, 2, 3], array([2, 3, 4]), None, <3x1 sparse matrix ...>]
[[1, 2, 3], array([2, 3, 4]), None, <...Sparse...dtype 'int64'...shape (3, 1)>]
"""

result = [_make_indexable(X) for X in iterables]
Expand Down Expand Up @@ -1503,8 +1503,8 @@ def check_symmetric(array, *, tol=1e-10, raise_warning=True, raise_exception=Fal
>>> from scipy.sparse import csr_matrix
>>> sparse_symmetric_array = csr_matrix(symmetric_array)
>>> check_symmetric(sparse_symmetric_array)
<3x3 sparse matrix of type '<class 'numpy.int64'>'
with 6 stored elements in Compressed Sparse Row format>
<Compressed Sparse Row sparse matrix of dtype 'int64'
with 6 stored elements and shape (3, 3)>
"""
if (array.ndim != 2) or (array.shape[0] != array.shape[1]):
raise ValueError(
Expand Down