Skip to content

Replace np.bool_ with np_bool in _ranking.py #31610

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

Conversation

MauryaGhogare
Copy link

This PR refactors np.bool_ to use the backported np_bool from _typing.py in sklearn/metrics/_ranking.py to ensure forward compatibility with future NumPy versions.

This is part of ongoing work to eliminate deprecated NumPy dtypes across the codebase.

Copy link

❌ Linting issues

This PR is introducing linting issues. Here's a summary of the issues. Note that you can avoid having linting issues by enabling pre-commit hooks. Instructions to enable them can be found here.

You can see the details of the linting issues under the lint job here


ruff check

ruff detected issues. Please run ruff check --fix --output-format=full locally, fix the remaining issues, and push the changes. Here you can see the detected issues. Note that the installed ruff version is ruff=0.11.7.


sklearn/linear_model/_logistic.py:1126:40: W291 Trailing whitespace
     |
1124 |     :ref:`sphx_glr_auto_examples_classification_plot_classification_probability.py`.
1125 |
1126 |     You can find a visual example here: 
     |                                        ^ W291
1127 |     :ref:`example_linear_model_plot_logistic_path`
     |
     = help: Remove trailing whitespace

sklearn/linear_model/_ridge.py:1513:89: E501 Line too long (89 > 88)
     |
1511 |     0.9595...
1512 |
1513 |     You can find a visual example here: :ref:`example_linear_model_plot_ridge_classifier`
     |                                                                                         ^ E501
     |

sklearn/metrics/_ranking.py:12:1: I001 [*] Import block is un-sorted or un-formatted
   |
10 |   # Authors: The scikit-learn developers
11 |   # SPDX-License-Identifier: BSD-3-Clause
12 | / from sklearn.utils._array_api import bool as np_bool
13 | |
14 | |
15 | | import warnings
16 | | from functools import partial
17 | | from numbers import Integral, Real
18 | |
19 | | import numpy as np
20 | | from scipy.integrate import trapezoid
21 | | from scipy.sparse import csr_matrix, issparse
22 | | from scipy.stats import rankdata
23 | |
24 | | from ..exceptions import UndefinedMetricWarning
25 | | from ..preprocessing import label_binarize
26 | | from ..utils import (
27 | |     assert_all_finite,
28 | |     check_array,
29 | |     check_consistent_length,
30 | |     column_or_1d,
31 | | )
32 | | from ..utils._array_api import (
33 | |     _max_precision_float_dtype,
34 | |     get_namespace_and_device,
35 | |     size,
36 | | )
37 | | from ..utils._encode import _encode, _unique
38 | | from ..utils._param_validation import Interval, StrOptions, validate_params
39 | | from ..utils.multiclass import type_of_target
40 | | from ..utils.sparsefuncs import count_nonzero
41 | | from ..utils.validation import _check_pos_label_consistency, _check_sample_weight
42 | | from ._base import _average_binary_score, _average_multiclass_ovo_score
   | |_______________________________________________________________________^ I001
   |
   = help: Organize imports

sklearn/metrics/_ranking.py:12:46: F401 [*] `sklearn.utils._array_api.bool` imported but unused
   |
10 | # Authors: The scikit-learn developers
11 | # SPDX-License-Identifier: BSD-3-Clause
12 | from sklearn.utils._array_api import bool as np_bool
   |                                              ^^^^^^^ F401
   |
   = help: Remove unused import: `sklearn.utils._array_api.bool`

Found 4 errors.
[*] 2 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option).

mypy

mypy detected issues. Please fix them locally and push the changes. Here you can see the detected issues. Note that the installed mypy version is mypy=1.15.0.


sklearn/metrics/_ranking.py:12: error: Module "sklearn.utils._array_api" has no attribute "bool"  [attr-defined]
Found 1 error in 1 file (checked 563 source files)

Generated for commit: a601e92. Link to the linter CI: here

@StefanieSenger
Copy link
Contributor

Closing as duplicates to #31606 and #31612.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants