-
-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
[MRG] Explicitly ignore SparseEfficiencyWarning in DBSCAN #13539
[MRG] Explicitly ignore SparseEfficiencyWarning in DBSCAN #13539
Conversation
Thanks for this, though we really shouldn't be using ignore_warnings except
in test code. I'd rather change dbscan: if we must ignore warnings we
should ignore specific warnings only.
|
Mea culpa for approving the use of ignore_warnings in library code!
|
My mistake. We should definitely replace I double checked that it is the only use of |
I've commented out the |
Oops, hadn't seen your answer @TomDLT. I will make the change. |
cdb1f80
to
e7abd0a
Compare
I was able to reproduce the warning with |
Please add commits rather than force pushing where possible |
Thanks @peay ! |
…it-learn#13539)" This reverts commit cd7764d.
…it-learn#13539)" This reverts commit cd7764d.
What does this implement/fix? Explain your changes.
py is a commonly used library, which has various utility subpackages, one of them being
apipkg
which implements lazy loading of Python modules.py
is marked as a runtime dependency of more than 9K packages on PyPI, so it isn't too easy to avoid.Importing py itself directly lazily loads certain packages like
py.test
. Lazy module loading is implemented by adding tosys.modules
anapipkg.AliasModule
, which implements__getattribute__
as:When
py.test
is not installed or cannot be imported, this result insys.modules["py.test"]
(and a few others) beingAliasModule
instances for whichmodule.__warningregistry__
isNone
(as are all attributes).This is causing issues with
sklearn
. Here is an example I've been hitting although I suspect there could be other occurences:ignore_warnings
to silence warnings.ignore_warnings
in turns relies onclean_warning_registry
.This makes it impossible to run
DBSCAN
oncepy
has been imported, becauseclean_warning_registry
is callingclear()
on all modules that have a__warningregistry__
attribute:This PR adds an additional check that
__warningregistry__
is a dictionnary.Any other comments?
I am not familiar enough with the project to know how we would want this to be fixed. In particular:
The issue really stems from
py
's lazily loaded modules, and one may wonder whethersklearn
should be worrying about this at all. Here, the issue could also be fixed by making surepy.test
can be imported.However,
__warningregistry__
isn't really documented either, and one could argue thatsklearn
should be checking whether it is a dictionnary before callingclear
on it.I'll let the maintainers decide whether this small additional check makes sense, in spite of this being a fix for a rather specific problem.