Repository: statsmodels/statsmodels

Issue:
statmodels sets warning filter "always" for all UserWarnings
Why does https://github.com/statsmodels/statsmodels/commit/2c0a583d2ed69a6ee6c86f51862a9bd4c23005e3  do the following?

```
warnings.simplefilter('always', category=UserWarning)
```

It very aggressively sets the "always" action for **all** UserWarnings, regardless of where they are defined or triggered.

Example issue: just by importing `seaborn` (which has statsmodels as dependency) in a jupyter notebook, I was flooded with repetitive warnings instead of just a single one: https://github.com/mwaskom/seaborn/issues/1446




Discussion:
My guess is that statsmodels wants to use warnings to report (potential) problems with model specification, so there it makes sense (like, if you set up a bad model, and get a warning, and then change it to a different bad model, you want to get a second warning).

It's probably reasonable to think that `UserWarning` should often be issued in that kind of context (if the user keeps doing the bad thing, keep warning them), but numpy's `VisibleDeprecationWarning` inherits from `UserWarning`, which I guess is what makes it visible!

As a suggestion to statsmodels, what if you defined a subclass of `UserWarning` called, e.g, `ModelWarning` and set *that* to always fire, reducing side-effects for other packages?
> what if you defined a subclass of UserWarning called, e.g, ModelWarning and set that to always fire

good idea, I thought we will have to add a loop to set each specific warning to always.

Thanks for reporting. I guess I was too enthusiastic about the warnings. (but I thought a DeprecationWarning or other python warnings would not be UserWarnings.)

Yes, the point is that we always want to warn when a model or function runs into problems with the data, similar to RuntimeWarnings issued by numpy 
(Although we still have noise RuntimeWarnings where we don't silence the RuntimeWarnings even if it is expected by design.)

We can backport this if we make a 0.9.1 release.

Resolving patch:
diff --git a/statsmodels/tools/sm_exceptions.py b/statsmodels/tools/sm_exceptions.py
--- a/statsmodels/tools/sm_exceptions.py
+++ b/statsmodels/tools/sm_exceptions.py
@@ -48,8 +48,11 @@ class ModuleUnavailableWarning(Warning):
 """
 
 
+class ModelWarning(UserWarning):
+    pass
+
 
-class ConvergenceWarning(UserWarning):
+class ConvergenceWarning(ModelWarning):
     pass
 
 
@@ -58,11 +61,11 @@ class ConvergenceWarning(UserWarning):
 """
 
 
-class CacheWriteWarning(UserWarning):
+class CacheWriteWarning(ModelWarning):
     pass
 
 
-class IterationLimitWarning(UserWarning):
+class IterationLimitWarning(ModelWarning):
     pass
 
 
@@ -71,55 +74,55 @@ class IterationLimitWarning(UserWarning):
 """
 
 
-class InvalidTestWarning(UserWarning):
+class InvalidTestWarning(ModelWarning):
     pass
 
 
-class NotImplementedWarning(UserWarning):
+class NotImplementedWarning(ModelWarning):
     pass
 
 
-class OutputWarning(UserWarning):
+class OutputWarning(ModelWarning):
     pass
 
 
-class DomainWarning(UserWarning):
+class DomainWarning(ModelWarning):
     pass
 
 
-class ValueWarning(UserWarning):
+class ValueWarning(ModelWarning):
     pass
 
 
-class EstimationWarning(UserWarning):
+class EstimationWarning(ModelWarning):
     pass
 
 
-class SingularMatrixWarning(UserWarning):
+class SingularMatrixWarning(ModelWarning):
     pass
 
 
-class HypothesisTestWarning(UserWarning):
+class HypothesisTestWarning(ModelWarning):
     pass
 
 
-class InterpolationWarning(UserWarning):
+class InterpolationWarning(ModelWarning):
     pass
 
 
-class PrecisionWarning(UserWarning):
+class PrecisionWarning(ModelWarning):
     pass
 
 
-class SpecificationWarning(UserWarning):
+class SpecificationWarning(ModelWarning):
     pass
 
 
-class HessianInversionWarning(UserWarning):
+class HessianInversionWarning(ModelWarning):
     pass
 
 
-class ColinearityWarning(UserWarning):
+class ColinearityWarning(ModelWarning):
     pass
 
-warnings.simplefilter('always', category=UserWarning)
+warnings.simplefilter('always', category=ModelWarning)


Test patch: