[MRG] Explicitly ignore SparseEfficiencyWarning in DBSCAN#13539
[MRG] Explicitly ignore SparseEfficiencyWarning in DBSCAN#13539TomDLT merged 1 commit intoscikit-learn:masterfrom
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
apipkgwhich implements lazy loading of Python modules.pyis 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.modulesanapipkg.AliasModule, which implements__getattribute__as:When
py.testis not installed or cannot be imported, this result insys.modules["py.test"](and a few others) beingAliasModuleinstances 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_warningsto silence warnings.ignore_warningsin turns relies onclean_warning_registry.This makes it impossible to run
DBSCANoncepyhas been imported, becauseclean_warning_registryis 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 whethersklearnshould be worrying about this at all. Here, the issue could also be fixed by making surepy.testcan be imported.However,
__warningregistry__isn't really documented either, and one could argue thatsklearnshould be checking whether it is a dictionnary before callingclearon 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.