From cb84ad60c55461f1f345109c70fc513820d37af5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Est=C3=A8ve?= Date: Tue, 2 Jul 2024 15:07:35 +0200 Subject: [PATCH 1/2] Fix scipy 1.14 doctest --- sklearn/conftest.py | 3 +++ sklearn/feature_extraction/image.py | 3 +++ sklearn/utils/_indexing.py | 8 ++++---- sklearn/utils/validation.py | 6 +++--- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/sklearn/conftest.py b/sklearn/conftest.py index 203c524561fdd..21aa763de5e8c 100644 --- a/sklearn/conftest.py +++ b/sklearn/conftest.py @@ -211,6 +211,9 @@ 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" + # 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 diff --git a/sklearn/feature_extraction/image.py b/sklearn/feature_extraction/image.py index 5c7d6efd7fa24..1189618f07feb 100644 --- a/sklearn/feature_extraction/image.py +++ b/sklearn/feature_extraction/image.py @@ -234,6 +234,9 @@ def grid_to_graph( >>> mask[[1, 2], [1, 2], :] = True >>> graph = grid_to_graph(*shape_img, mask=mask) >>> print(graph) + + Coords Values (0, 0) 1 (1, 1) 1 """ diff --git a/sklearn/utils/_indexing.py b/sklearn/utils/_indexing.py index ca2327f2bb109..11ecdfe0ecbd9 100644 --- a/sklearn/utils/_indexing.py +++ b/sklearn/utils/_indexing.py @@ -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> + >>> X_sparse.toarray() array([[1., 0.], @@ -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> + >>> X_sparse.toarray() array([[0., 0.], diff --git a/sklearn/utils/validation.py b/sklearn/utils/validation.py index 228fbe76a25e1..af9fdb4a79cba 100644 --- a/sklearn/utils/validation.py +++ b/sklearn/utils/validation.py @@ -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] @@ -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 '' - with 6 stored elements in Compressed Sparse Row format> + """ if (array.ndim != 2) or (array.shape[0] != array.shape[1]): raise ValueError( From 1e63b2b87d7db7ea60d3b59651d68781174907af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Est=C3=A8ve?= Date: Tue, 2 Jul 2024 16:37:15 +0200 Subject: [PATCH 2/2] fix --- sklearn/conftest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sklearn/conftest.py b/sklearn/conftest.py index 21aa763de5e8c..79fd695fb64f1 100644 --- a/sklearn/conftest.py +++ b/sklearn/conftest.py @@ -211,8 +211,9 @@ 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"): + 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: