Skip to content

statmodels sets warning filter "always" for all UserWarnings #4711

Closed

Description

@soxofaan

Why does 2c0a583 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: mwaskom/seaborn#1446

Activity

  1. mwaskom commented on Jun 5, 2018

    @mwaskom

    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?

  2. added this to the 0.9 milestone on Jun 5, 2018
  3. josef-pkt commented on Jun 5, 2018

    @josef-pkt
    Member

    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.

  4. added 2 commits that reference this issue on Jun 5, 2018
    df044a7
    4d7ca89
  5. soxofaan commented on Jun 5, 2018

    @soxofaan
    ContributorAuthor

    created pull requests #4712 (for master) and #4713 (for 0.9.x branch)

  6. soxofaan commented on Jun 22, 2018

    @soxofaan
    ContributorAuthor

    FYI, my current workaround to suppress repetitive user warnings in Jupyter notebooks is to add this to the notebook:

    import warnings
    warnings.simplefilter('once', category=UserWarning)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions