Skip to content

Include scipy-stubs in the type-check dependencies#6174

Merged
not522 merged 10 commits intooptuna:masterfrom
jorenham:patch-1
Jul 2, 2025
Merged

Include scipy-stubs in the type-check dependencies#6174
not522 merged 10 commits intooptuna:masterfrom
jorenham:patch-1

Conversation

@jorenham
Copy link
Copy Markdown
Contributor

I noticed some other stubs-only packages, so I figured you might also be interested in scipy-stubs.
And in case it matters (for CI runtime perhaps), scipy doesn't explicitly require scipy. It's also very lightweight, and it requires no mypy plugins, imports, or configuration.

@jorenham
Copy link
Copy Markdown
Contributor Author

I'll take a look at the mypy errors

@codecov
Copy link
Copy Markdown

codecov bot commented Jun 22, 2025

Codecov Report

Attention: Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 88.38%. Comparing base (5ccdf30) to head (7cefd09).
Report is 87 commits behind head on master.

Files with missing lines Patch % Lines
optuna/pruners/_wilcoxon.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6174      +/-   ##
==========================================
- Coverage   88.40%   88.38%   -0.03%     
==========================================
  Files         207      207              
  Lines       14029    14030       +1     
==========================================
- Hits        12402    12400       -2     
- Misses       1627     1630       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nabenabe0928 nabenabe0928 requested a review from Copilot June 25, 2025 04:48
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds the "scipy-stubs" package to the type-check dependencies and makes necessary adjustments in the code to properly handle type-checking issues related to SciPy stubs. Key changes include:

  • Updating test files to include detailed comments and type ignores referencing known scipy-stubs issues.
  • Adding "scipy-stubs" to pyproject.toml with a Python version marker.
  • Modifying functions in pruner and GP modules to improve type safety and compatibility with the new stubs.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/samplers_tests/tpe_tests/test_truncnorm.py Added inline comments and type ignores for SciPy stubs compatibility.
pyproject.toml Added "scipy-stubs" as a dependency for Python 3.10 and above.
optuna/pruners/_wilcoxon.py Introduced a Literal type annotation and explicit bool conversion to safely handle np.bool_ values.
optuna/_gp/search_space.py Updated Sobol engine instantiation to include a type ignore comment referencing a related SciPy stubs issue.
optuna/_gp/optim_mixed.py Added a type ignore comment on function parameter to address type-check issues per a reported SciPy stubs issue.
Comments suppressed due to low confidence (3)

optuna/_gp/search_space.py:106

  • [nitpick] Consider expanding the comment to briefly explain the underlying issue referenced in scipy/scipy-stubs#644 to aid future maintainers.
        qmc_engine = qmc.Sobol(  # type: ignore[call-arg]

optuna/_gp/optim_mixed.py:64

  • [nitpick] It might be helpful to add a concise note explaining why a type ignore is needed here (referencing scipy/scipy-stubs#645) to assist future maintainers.
        func=negative_acqf_with_grad,  # type: ignore[arg-type]

optuna/pruners/_wilcoxon.py:225

  • Explicitly converting np.bool_ to bool is good practice; ensure that similar conversions are applied consistently across the codebase for uniform behavior.
        return bool(p < self._p_threshold)

@nabenabe0928 nabenabe0928 added the enhancement Change that does not break compatibility and not affect public interfaces, but improves performance. label Jun 25, 2025
@nabenabe0928
Copy link
Copy Markdown
Contributor

@jorenham
Hey, thank you for the PR!

@not522
Could you review this PR?

@nabenabe0928
Copy link
Copy Markdown
Contributor

To avoid a large conflict, let me check this PR again after the following PR is merged:

Cc: > @not522

@jorenham
Copy link
Copy Markdown
Contributor Author

To avoid a large conflict, let me check this PR again after the following PR is merged:

I don't think there's anything there that would cause merge conflicts here.

Copy link
Copy Markdown
Member

@not522 not522 left a comment

Choose a reason for hiding this comment

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

Thank you for your PR! Since scipy-stubs has been updated, please make corresponding updates. 🙏

Co-authored-by: Naoto Mizuno <gobou522@gmail.com>
Comment on lines +54 to +57
a_arr, b_arr = np.array([a]), np.array([b])
assert truncnorm_ours._log_gauss_mass(a_arr, b_arr) == pytest.approx(
_log_gauss_mass_scipy(a_arr, b_arr), nan_ok=True
), f"_log_gauss_mass(a={a}, b={b})"
Copy link
Copy Markdown
Contributor Author

@jorenham jorenham Jul 1, 2025

Choose a reason for hiding this comment

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

I noticed that the x was unused, so I removed the loop; hope you don't mind.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@jorenham
Thank you for the catch!

@not522
Do you think we need to do a follow-up for this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

While strictly speaking this change should be in a separate PR, but I think it's acceptable to do it in this PR.

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!

Copy link
Copy Markdown
Member

@not522 not522 left a comment

Choose a reason for hiding this comment

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

LGTM!

@not522 not522 merged commit 01aa711 into optuna:master Jul 2, 2025
24 of 27 checks passed
@not522 not522 added this to the v4.5.0 milestone Jul 2, 2025
@jorenham jorenham deleted the patch-1 branch July 2, 2025 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Change that does not break compatibility and not affect public interfaces, but improves performance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants