Replace mutables used as defaults in functions with placeholder defaults
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
statsmodels |
Fix Committed
|
Undecided
|
Unassigned |
Bug Description
There are places where we have got class constructor calls in the
function defaults,
e.g.
def __init__(self, endog, exog, family=
The Gaussian constructor will be called when the module is imported, not when the function is called, therefore all calls to __init__ that use the default will be sharing the same instance of the default object.
If we want the default evaluated when it called, then you need
something like:
def __init__(self, endog, exog, family=None):
if family is None:
family = family.Gaussian()
or
def __init__(self, endog, exog, family=
if family = family.Default():
Changed in statsmodels: | |
status: | New → Fix Committed |
What about something like this, I don't know if it seems more or less intuitive
class Gaussian(object):
def __init__(self, **kwargs):
self.link = kwargs.get('link', 'default')
self.alpha = kwargs.get('alpha', 'default')
class GLM(object): **family_ kwargs)
def __init__(self, family=Gaussian, family_kwargs={}):
self.family = family(
A = GLM(family_ kwargs= dict(link = 10, alpha = 25))
print A.family.link
A.family.link = 50
print A.family.link
print A.family.alpha
B = GLM()
print B.family.link
print B.family.alpha