From 7dfa9d09f43973a911901b5191fab999357d3597 Mon Sep 17 00:00:00 2001 From: Olivier Grisel Date: Mon, 2 Dec 2024 18:07:24 +0100 Subject: [PATCH 1/4] Fix test_csr_polynomial_expansion_index_overflow on [scipy-dev] --- sklearn/preprocessing/tests/test_polynomial.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sklearn/preprocessing/tests/test_polynomial.py b/sklearn/preprocessing/tests/test_polynomial.py index b97500d43ef73..53b33e8a2432e 100644 --- a/sklearn/preprocessing/tests/test_polynomial.py +++ b/sklearn/preprocessing/tests/test_polynomial.py @@ -1123,13 +1123,14 @@ def test_csr_polynomial_expansion_index_overflow( return X_trans = pf.fit_transform(X) - expected_dtype = np.int64 if num_combinations > np.iinfo(np.int32).max else np.int32 + expected_dtype_min_bits = 64 if num_combinations > np.iinfo(np.int32).max else 32 # Terms higher than first degree non_bias_terms = 1 + (degree - 1) * int(not interaction_only) expected_nnz = int(include_bias) + non_bias_terms assert X_trans.dtype == X.dtype assert X_trans.shape == (1, pf.n_output_features_) - assert X_trans.indptr.dtype == X_trans.indices.dtype == expected_dtype + assert np.iinfo(X_trans.indptr.dtype).bits >= expected_dtype_min_bits + assert np.iinfo(X_trans.indices.dtype).bits >= expected_dtype_min_bits assert X_trans.nnz == expected_nnz if include_bias: From 8a7e24636a85cc74b862fa056f61e97d6a2fba6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Est=C3=A8ve?= Date: Wed, 4 Dec 2024 11:37:54 +0100 Subject: [PATCH 2/4] Use int32 indices as much as we can --- sklearn/preprocessing/tests/test_polynomial.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sklearn/preprocessing/tests/test_polynomial.py b/sklearn/preprocessing/tests/test_polynomial.py index 53b33e8a2432e..cb6715f1d3124 100644 --- a/sklearn/preprocessing/tests/test_polynomial.py +++ b/sklearn/preprocessing/tests/test_polynomial.py @@ -1050,8 +1050,10 @@ def test_csr_polynomial_expansion_index_overflow( `scipy.sparse.hstack`. """ data = [1.0] - row = [0] - col = [n_features - 1] + # Use int32 indices as much as we can + indices_dtype = np.int32 if n_features - 1 <= np.iinfo(np.int32).max else np.int64 + row = np.array([0], dtype=indices_dtype) + col = np.array([n_features - 1], dtype=indices_dtype) # First degree index expected_indices = [ From 337225040c0215d485eddf92c32d32921b13fd9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Est=C3=A8ve?= Date: Wed, 4 Dec 2024 11:38:13 +0100 Subject: [PATCH 3/4] Revert "Fix test_csr_polynomial_expansion_index_overflow on [scipy-dev]" This reverts commit 7dfa9d09f43973a911901b5191fab999357d3597. --- sklearn/preprocessing/tests/test_polynomial.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sklearn/preprocessing/tests/test_polynomial.py b/sklearn/preprocessing/tests/test_polynomial.py index cb6715f1d3124..9a98ba25e9d8b 100644 --- a/sklearn/preprocessing/tests/test_polynomial.py +++ b/sklearn/preprocessing/tests/test_polynomial.py @@ -1125,14 +1125,13 @@ def test_csr_polynomial_expansion_index_overflow( return X_trans = pf.fit_transform(X) - expected_dtype_min_bits = 64 if num_combinations > np.iinfo(np.int32).max else 32 + expected_dtype = np.int64 if num_combinations > np.iinfo(np.int32).max else np.int32 # Terms higher than first degree non_bias_terms = 1 + (degree - 1) * int(not interaction_only) expected_nnz = int(include_bias) + non_bias_terms assert X_trans.dtype == X.dtype assert X_trans.shape == (1, pf.n_output_features_) - assert np.iinfo(X_trans.indptr.dtype).bits >= expected_dtype_min_bits - assert np.iinfo(X_trans.indices.dtype).bits >= expected_dtype_min_bits + assert X_trans.indptr.dtype == X_trans.indices.dtype == expected_dtype assert X_trans.nnz == expected_nnz if include_bias: From d9497916b6cc5adfcaec09fc091cd498f31db1dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Est=C3=A8ve?= Date: Wed, 4 Dec 2024 11:38:28 +0100 Subject: [PATCH 4/4] [azure parallel] [scipy-dev]