Skip to content

Fix a mypy error when using numpy>=2.2.4#212

Merged
HideakiImamura merged 1 commit intooptuna:mainfrom
c-bata:fix-lightgbm-mypy-error
Mar 19, 2025
Merged

Fix a mypy error when using numpy>=2.2.4#212
HideakiImamura merged 1 commit intooptuna:mainfrom
c-bata:fix-lightgbm-mypy-error

Conversation

@c-bata
Copy link
Copy Markdown
Member

@c-bata c-bata commented Mar 19, 2025

Motivation

With Numpy=2.2.4, mypy raises following errors.
https://github.com/optuna/optuna-integration/actions/runs/13935185091/job/39001498800

$ mypy optuna_integration/_lightgbm_tuner/
Success: no issues found in 5 source files
$ pip install -U numpy
Requirement already satisfied: numpy in ./venv/lib/python3.11/site-packages (2.1.3)
Collecting numpy
  Downloading numpy-2.2.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (62 kB)
Downloading numpy-2.2.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (16.4 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 16.4/16.4 MB 84.9 MB/s eta 0:00:00
Installing collected packages: numpy
  Attempting uninstall: numpy
    Found existing installation: numpy 2.1.3
    Uninstalling numpy-2.1.3:
      Successfully uninstalled numpy-2.1.3
Successfully installed numpy-2.2.4

[notice] A new release of pip is available: 24.3.1 -> 25.0.1
[notice] To update, run: pip install --upgrade pip
$ mypy optuna_integration/_lightgbm_tuner/
optuna_integration/_lightgbm_tuner/optimize.py:561: error: Incompatible types in assignment (expression has type "list[str]", variable has type "str")  [assignment]
optuna_integration/_lightgbm_tuner/optimize.py:561: error: Unsupported operand types for >= ("str" and "float")  [operator]
optuna_integration/_lightgbm_tuner/optimize.py:561: error: Unsupported operand types for <= ("str" and "float")  [operator]
Found 3 errors in 1 file (checked 5 source files)

Description of the changes

To address the above issue, the type of the param_values variable is cast using typing.cast.

@c-bata c-bata added the CI Continuous integration. label Mar 19, 2025
@c-bata
Copy link
Copy Markdown
Member Author

c-bata commented Mar 19, 2025

@HideakiImamura Could you review this PR?

Copy link
Copy Markdown
Member

@HideakiImamura HideakiImamura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@HideakiImamura HideakiImamura merged commit 63ab581 into optuna:main Mar 19, 2025
26 checks passed
@c-bata c-bata deleted the fix-lightgbm-mypy-error branch March 21, 2025 00:55
@y0z y0z added this to the v4.3.0 milestone Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI Continuous integration.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants