Skip to content
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

Specify stacklevel for warnings.warn for more helpful warning message. #1419

Merged
merged 1 commit into from Jun 24, 2020

Conversation

harupy
Copy link
Contributor

@harupy harupy commented Jun 24, 2020

Motivation

By default (stacklevel=1), a warning raised by warnings.warn generates a message like below.

> python test.py
/path/to/optuna/_experimental.py:86: ExperimentalWarning:

HyperbandPruner is experimental (supported from v1.1.0). The interface can change in the future.

This message shows the line of code that the warning originates from rather than where the deprecated function or class is called.

This PR fixes it by specifying stacklevel for warnings.warn. After the fix, a warning message should look like:

/path/to/file_that_calls_HyperbandPruner.py:6: ExperimentalWarning:

HyperbandPruner is experimental (supported from v1.1.0). The interface can change in the future.

https://docs.python.org/2/library/warnings.html#warnings.warn

Description of the changes

Specify stacklevel in warnings.warn.

@harupy harupy changed the title Specify stacklevel in warnings.warn for more helpful warning message. Specify stacklevel for warnings.warn for more helpful warning message. Jun 24, 2020
@codecov-commenter
Copy link

Codecov Report

Merging #1419 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1419   +/-   ##
=======================================
  Coverage   88.04%   88.04%           
=======================================
  Files          98       98           
  Lines        7397     7397           
=======================================
  Hits         6513     6513           
  Misses        884      884           
Impacted Files Coverage Δ
optuna/_deprecated.py 100.00% <ø> (ø)
optuna/_experimental.py 100.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4d6e1c7...cc45cf2. Read the comment docs.

@HideakiImamura HideakiImamura added the enhancement Change that does not break compatibility and not affect public interfaces, but improves performance. label Jun 24, 2020
Copy link
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.

Thanks for your contribution as always! It is reasonable to increase the stacklevel for decorators. LGTM.

Copy link
Member

@toshihikoyanase toshihikoyanase left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you for your contribution.

I confirmed that this change worked as expected using LightGBMTuner.best_booster, optuna.structs.TrialPruned, and GridSampler.

@toshihikoyanase toshihikoyanase merged commit 86a4b89 into optuna:master Jun 24, 2020
@toshihikoyanase toshihikoyanase added this to the v2.0.0 milestone Jun 24, 2020
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.

None yet

4 participants