-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
[python-package] make LGBMDeprecationWarning inherit from FutureWarning #6447
Conversation
I think we should use
So if someone has code wrapping LightGBM in a separate file and call it from another script they'll never see these warnings. With the current setup those warnings are always shown, since
That PEP's description of
|
Example of pandas using |
Gah I'm just not sure. I had
I also see many examples of Interestingly, looks like class ModuleDeprecationWarning(DeprecationWarning):
"""Module deprecation warning.
.. warning::
This warning should not be used, since nose testing is not relevant
anymore.
The nose tester turns ordinary Deprecation warnings into test failures.
That makes it hard to deprecate whole modules, because they get
imported by default. So this is a special Deprecation warning that the
nose tester will let pass without making tests fail.
"""
pass
class VisibleDeprecationWarning(UserWarning):
"""Visible deprecation warning.
By default, python will not show deprecation warnings, so this class
can be used when a very visible warning is helpful, for example because
the usage is most likely a user bug.
"""
pass But then sometimes doesn't even use it, and uses I don't know what to do any more 😭 . Maybe we should just leave this alone (close this PR) until there's a clearer reason to prefer one specific pattern to another? |
Reading through PEP-565, I'd be in favor of using |
My main concern here is the actual outcome with respect to warning category, rather than the theoretical intent. Consider the following example: Suppose I have a file import warnings
def f():
warnings.warn("hi", category=DeprecationWarning)
if __name__ == '__main__':
f() which emulates what LightGBM would be doing. And another file from deprecated import f
def g():
f()
if __name__ == '__main__':
g() If I run /hdd/github/LightGBM/my_module/deprecated.py:4: DeprecationWarning: hi
warnings.warn("hi", category=DeprecationWarning) However, if I run If I change the warning category to So we'd be basically changing the warning visibility and people that wrap LightGBM code wouldn't be aware of the deprecation. |
I've read back through the PEP, and I agree with @jmoralez 's reasoning... we should use I think we want the warnings to be loud, to move as many downstream users (both library developers and people training/serving models directly) to non-deprecated behavior as possible before future releases that remove that behavior. I've pushed a commit switching it to Also note that the only uses of this right now are for warnings that have never been in a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I think we should just update the title.
🙈 absolutely right, thanks @jmoralez . Just updated it. |
Contributes to #6435 .
LGBMDeprecationWarning
was added 7 years ago, in #1046. That was done because Python's builtinDeprecationWarning
is not shown by default.PEP 565, accepted in November 2017, offers a different prescription for this.
(PEP-565)
This change will also ensure such warnings show up in tests of anything using
lightgbm
which usepytest
to run their tests.From the
pytest
docs:("DeprecationWarning and PendingDeprecationWarning")