Skip to content

Remove un-picklable method in __getstate__ - #3678

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

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

Conversation

@jbrockmendel

@jbrockmendel jbrockmendel commented May 20, 2017 •

Copy link
Copy Markdown
Contributor

Add a test that fails without this fix. In particular, cov_params_func key gets set in fit_regularized.

The test is taken directly from GH #2686

Add a test that fails without this fix.  In particular, cov_params_func key gets set in fit_regularized.

The test is taken directly from GH#2686
@coveralls

coveralls commented May 20, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.004%) to 90.437% when pulling 75455f0 on jbrockmendel:fit_reg_pickle into 90e2af8 on statsmodels:master.

@josef-pkt

Copy link
Copy Markdown
Member

in general, when we take over commits or PRs, then we should preserve the original author.

except (AttributeError, KeyError):
pass
# remove unpicklable methods
self.mle_settings['callback'] = None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This removes the try ... except protection for the case when 'callback' is not available.
It doesn't sound like a required key.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, catching the AttributeError was added in case mle_settings itself also doesn't exist.
(I think OLS and similar linear algebra models don't have it but the unit tests don't fail (?).)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silly me, that's in discrete_model and not in base All discrete models use currently scipy optimizers and have mle_setting, so there is no failing test case here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not clear on why there was a try/except in the first place. KeyError shouldn't occur (maybe confusion with __setstate__?). AttributeError would make sense if there is no mle_settings I guess, but I don't think that case is relevant is it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember if there was a case where it failed.
Maybe it was just risk aversion to imposing details that are not important or required parts of the general interface, i.e. defensive programming. Or it was written in analogy to a base function.
Or just generic future proofness, in case we add estimators that don't define mle_settings and a callback key.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better safe than sorry.
I think I want to keep both mle_settings and 'callback' optional. Two extra if won't change performance.
e.g. we, or somebody, might replace the fit method, e.g. if we use GLMNet type of coordinate descend.

@jbrockmendel

Copy link
Copy Markdown
Contributor Author

in general, when we take over commits or PRs, then we should preserve the original author.

What's the appropriate fix? Add a comment in the test?

@josef-pkt

Copy link
Copy Markdown
Member

What's the appropriate fix? Add a comment in the test?

Note, I'm making a lot of maintainer comments to you, especially for workflow and details that might not be described or only spread out over parts of the documentation, in case you want to get more into the details of maintenance work. (given that you are already doing a lot of maintenance and review work)

I'm not sure yet if we want to fix it here. The way to preserve the original author is to use the initial commits or PR and then add the additional changes in new commits. I.e. my usual workflow is
checkout PR - rebase/fix commits if necessary - add changes/new commits - make new PR - review -> merge

@jbrockmendel

Copy link
Copy Markdown
Contributor Author

Note, I'm making a lot of maintainer comments to you

To clarify: are my attempts to help being a net drain on your time? If so then I've messed up and will change... something. If not, then I appreciate you helping with my Git-fu.

I'm not sure yet if we want to fix it here

I've been procrastinating on "real" work by spending time here. I'm going to take this as an excuse to whittle down my statsmodels to-do list for the time being.

@jbrockmendel

Copy link
Copy Markdown
Contributor Author

@josef-pkt the content of this PR should be good to go. Based on the discussion above it sounds like you want me to add comment(s) somewhere to ensure appropriate attribution. If you can clarify what you're looking for, I'll add it and we can wrap this up.

@josef-pkt

Copy link
Copy Markdown
Member

I will rebase, add two ifs, and get it ready for merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants