Skip to content

REF/ENH: verify valid model.__init__ keywords #3890

Open

Description

@josef-pkt

e.g. #3889

using **kwargs is dangerous for usage because there is no error for wrong and misspelled keywords.

We already have _init_keys and we should be able to expand the usage for checking that only valid keywords are given by the user.
This would also enforce that _init_keys have the correct list, e.g. #3888

We might have to distinguish different keyword types, e.g. missing will not be necessary if we recreate a model based on the attached data, endog, exog and similar.

Activity

  1. jbrockmendel commented on Aug 28, 2017

    @jbrockmendel
    Contributor

    How many "+1"s am I allowed to give? That. I give that many.

    One option would be to define something at the class level like _kwd_whitelist = frozenset(['endog', 'weights'])

  2. josef-pkt commented on Aug 28, 2017

    @josef-pkt
    MemberAuthor

    We already have _init_keys and I would like to avoid adding more that need to be updated in each model class.
    I don't remember all the details as became obvious in #3888,

    One danger: #3605 whitelists can be painful for enhancements.

    (using a different search term I find now also)
    #2163 general **kwargs problem
    #1732 explanation/design of _init_keys for recreating models

  3. josef-pkt commented on Aug 28, 2017

    @josef-pkt
    MemberAuthor

    maybe we need a separate whitelist after all.
    The _init_keys are always (?) explicit keywords in the final model (leaves of the inheritance tree), so **kwargs should at most contain generic keywords like missing.
    That is, we would only need to check that there is nothing left in the kwargs.

    However, there is still the issue where we enforce this. because the base classes have more in kwargs than just the extras like missing. Also, not all keywords are handed off to the super class __init__.

    Maybe simpler:
    checking NegativeBinomial as an example: **kwargs is most likely an unused generalization, i.e. future proofing in case we add new generic keywords (like when we added missing)
    If we raise on invalid or not implemented keywords, then we should be able to just remove the kwargs in the final models.
    On the other hand a generic whitelist for extra **kwargs in base would only require one change to add a new valid keyword to all models.

  4. josef-pkt commented on Aug 28, 2017

    @josef-pkt
    MemberAuthor

    One possible new generic keyword will be how to treat singular exog.

    Another keyword inside discrete is to add offset to all models, but that needs enough changes in every model so we can add it explicitly without much extra work.

  5. added this to the 0.10 milestone on Oct 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions