Skip to content

Make keyword args explicit - #4019

Closed
jbrockmendel wants to merge 1 commit into
statsmodels:masterfrom
jbrockmendel:defaults
Closed

jbrockmendel wants to merge 1 commit into
statsmodels:masterfrom
jbrockmendel:defaults

Conversation

@jbrockmendel

Copy link
Copy Markdown
Contributor

No description provided.

@coveralls

coveralls commented Oct 11, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.002%) to 81.639% when pulling 48da686 on jbrockmendel:defaults into 326ae0c on statsmodels:master.

@codecov-io

codecov-io commented Oct 11, 2017 •

Copy link
Copy Markdown

Codecov Report

Merging #4019 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4019      +/-   ##
==========================================
- Coverage   79.32%   79.32%   -0.01%     
==========================================
  Files         544      544              
  Lines       81714    81710       -4     
  Branches     9255     9253       -2     
==========================================
- Hits        64820    64816       -4     
  Misses      14800    14800              
  Partials     2094     2094
Impacted Files Coverage Δ
statsmodels/base/data.py 89.75% <100%> (-0.05%) ⬇️
statsmodels/base/model.py 82.58% <100%> (-0.06%) ⬇️
statsmodels/multivariate/multivariate_ols.py 81.37% <0%> (-0.81%) ⬇️
statsmodels/tsa/vector_ar/vecm.py 93.87% <0%> (+0.24%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 11d1c18...b6ec72d. Read the comment docs.

@bashtage

Copy link
Copy Markdown
Member

@josef-pkt I approve of this cleaning

@josef-pkt

Copy link
Copy Markdown
Member

I'm not sure about the general design idea.

If we initialize the attributes in the superset of all models, then we get a large number of attributes that are None. That makes dir(object) less informative, and we carry redundant/unused attributes around.
IMO, all attributes except for a small required intersection set should be optional.

e.g. predict uses
if transform and hasattr(self.model, 'formula') and exog is not None

Given that unit tests pass, the data.formula is not automatically transmitted as attribute to the model

base.Model._handle_data excludes attaching formula and design_info to the model.
formula is explicitly attached to the model in base.Model.from_formula

@jbrockmendel

Copy link
Copy Markdown
Contributor Author

More predictability, fewer special cases --> Easier to reason about. Explicit is zen.

@josef-pkt

Copy link
Copy Markdown
Member

more attributes to worry about,
More generic stuff doesn't make special cases less special, it only replaces hasattr by is None

In any case, it's likely that I agree in this case, after I have time to think about it.
(And maybe not, currently all we need in a fake data instance or class is the xnames or param_names.)

@jbrockmendel

Copy link
Copy Markdown
Contributor Author

Going on a tangent because this is something interesting I learned about recently: hasattr behavior is subtly different between py2/py3.

hasattr (and much worse, setattr and delattr) make it harder to grep for e.g. "\.df_model"

And really is self.foo is not None more complicated than hasattr(self, 'foo')? Pretty sure the former is more performant.

@josef-pkt

Copy link
Copy Markdown
Member

The reason why we or I added many hasattr and getattr is that "everything is a special case", i.e. we are adding many attributes and features that are specific to certain use cases (using formulas) or specific to models.
As you have seen in many other issues, the question of what should be common, generically required attributes is still open, although the set is increasing over time.

example
df_resid = getattr(self, 'df_resid_inference', self.df_resid) (in base.model.LikelihoodModelResults.pvalues and t_test, ...)
handles a correction for panel or cluster robust standard errors if use_t=True, and has currently no other use. I did not promote it to a generically required or initialized attribute.

Some attributes can over time become generically required or initialized if the fraction of special cases that need it becomes large.

(I don't remember any bug that we had because of the behavior of hasattr or getattr, and I don't remember ever running into py 2 versus py 3 problems with them.)

@coveralls

coveralls commented Nov 2, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.0009%) to 81.886% when pulling b6ec72d on jbrockmendel:defaults into 11d1c18 on statsmodels:master.

@bashtage bashtage added the rejected Used for PRs with changes that are not acceptable label Jul 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rejected Used for PRs with changes that are not acceptable

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants