Repository navigation
[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.
"""
passBut 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 |
jmoralez
left a comment
There was a problem hiding this comment.
Thanks! I think we should just update the title.
|
π absolutely right, thanks @jmoralez . Just updated it. |
|
This pull request has been automatically locked since there has not been any recent activity since it was closed. |
Contributes to #6435 .
LGBMDeprecationWarningwas added 7 years ago, in #1046. That was done because Python's builtinDeprecationWarningis 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
lightgbmwhich usepytestto run their tests.From the
pytestdocs:("DeprecationWarning and PendingDeprecationWarning")