You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
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.
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.
Activity
jbrockmendel commentedon Aug 28, 2017
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'])josef-pkt commentedon Aug 28, 2017
We already have
_init_keysand 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
**kwargsproblem#1732 explanation/design of
_init_keysfor recreating modelsjosef-pkt commentedon Aug 28, 2017
maybe we need a separate whitelist after all.
The
_init_keysare always (?) explicit keywords in the final model (leaves of the inheritance tree), so**kwargsshould at most contain generic keywords likemissing.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:
**kwargsis 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
**kwargsinbasewould only require one change to add a new valid keyword to all models.josef-pkt commentedon Aug 28, 2017
One possible new generic keyword will be how to treat singular exog.
Another keyword inside discrete is to add
offsetto all models, but that needs enough changes in every model so we can add it explicitly without much extra work.