Skip to content

Move SciPy to the lazy import section in _gp/scipy_blas_thread_patch.py#6269

Merged
nabenabe0928 merged 1 commit intooptuna:masterfrom
Kaichi-Irie:fix-lazy-import-scipy_blas_thread_patch
Sep 9, 2025
Merged

Move SciPy to the lazy import section in _gp/scipy_blas_thread_patch.py#6269
nabenabe0928 merged 1 commit intooptuna:masterfrom
Kaichi-Irie:fix-lazy-import-scipy_blas_thread_patch

Conversation

@Kaichi-Irie
Copy link
Copy Markdown
Contributor

Import handling improvements:

Motivation

This pull request refactors the import logic for scipy in optuna/_gp/scipy_blas_thread_patch.py to improve performance and avoid unnecessary imports. Instead of always importing scipy, it now uses a lazy import mechanism unless type checking is active.

Description of the changes

  • Replaced the unconditional import of scipy with a conditional lazy import using _LazyImport, which helps defer loading scipy until it is actually needed.

@Kaichi-Irie Kaichi-Irie changed the title fix import structure for scipy in the context of type checking Fix: Lazy import of SciPy in optuna/_gp/scipy_blas_thread_patch.py Sep 8, 2025
@Kaichi-Irie Kaichi-Irie changed the title Fix: Lazy import of SciPy in optuna/_gp/scipy_blas_thread_patch.py Fix: Lazy import of SciPy in _gp/scipy_blas_thread_patch.py Sep 8, 2025
@nabenabe0928 nabenabe0928 changed the title Fix: Lazy import of SciPy in _gp/scipy_blas_thread_patch.py Move SciPy to the lazy import section in _gp/scipy_blas_thread_patch.py Sep 8, 2025
@nabenabe0928 nabenabe0928 added this to the v4.6.0 milestone Sep 8, 2025
@nabenabe0928 nabenabe0928 added the code-fix Change that does not change the behavior, such as code refactoring. label Sep 8, 2025
@nabenabe0928 nabenabe0928 self-assigned this Sep 8, 2025
Copy link
Copy Markdown
Contributor

@nabenabe0928 nabenabe0928 left a comment

Choose a reason for hiding this comment

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

LGTM!

@nabenabe0928 nabenabe0928 merged commit f043d20 into optuna:master Sep 9, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-fix Change that does not change the behavior, such as code refactoring.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants