Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: stats: make distribution instances picklable #4821

Merged
merged 3 commits into from Nov 30, 2015

Conversation

ev-br
Copy link
Member

@ev-br ev-br commented May 6, 2015

Intends to close gh-4816.

(this likely has a milestone "after 0.16 is done")

Note to self: multivariate distributions are likely OK, but it's worth checking.

@rgommers
Copy link
Member

rgommers commented May 7, 2015

It passes (except for pep8), but indeed I agree it would be better to merge this after the release split.

@ev-br
Copy link
Member Author

ev-br commented Oct 25, 2015

rebased.

@rgommers
Copy link
Member

Question: is it a problem that this loses changes to attributes that are made after instantiation (_ctor_param is never updated)? Not sure if there's a good use-case for doing that, but it may be something worth checking for.

@ev-br
Copy link
Member Author

ev-br commented Nov 22, 2015

Here's _ctor_param:

        self._ctor_param = dict(
            momtype=momtype, a=a, b=b, xtol=xtol,
            badvalue=badvalue, name=name, longname=longname,
            shapes=shapes, extradoc=extradoc, seed=seed)

a and b are either fixed or get regenerated at each call for some distributions, seed is related to the random_state which is taken care of separately here, the rest do not seem like something a user is very likely to change.

I also note that freezing distributions also relies on _ctor_param.

@rgommers
Copy link
Member

I noticed indeed that freezing does the same. It's odd though that there are a bunch of attributes that we aren't preventing users from changing, but assuming that they don't.

It would be easy to add a private method to update self._ctor_param and call that from freeze and from __getstate__. That would solve the issue.

Some of these can be changed by a user (unlikely but technically possible.)
Hence keep the originals *and* update them with current values
when pickling or freezing.
@ev-br
Copy link
Member Author

ev-br commented Nov 28, 2015

It would be easy to add a private method to update self._ctor_param and call that from freeze and from __getstate__. That would solve the issue

Done.

rgommers added a commit that referenced this pull request Nov 30, 2015
ENH: stats: make distribution instances picklable
@rgommers rgommers merged commit f13e808 into scipy:master Nov 30, 2015
@rgommers
Copy link
Member

Thanks Evgeni, merged.

@ev-br ev-br deleted the stats_pickle branch November 30, 2015 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new feature or improvement scipy.stats
Projects
None yet
Development

Successfully merging this pull request may close these issues.

scipy.stats.distributions.rv_frozen not picklable
2 participants