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

Swap to use more portable types than pickles #23

Merged
merged 2 commits into from
Jul 23, 2018

Conversation

ljwolf
Copy link
Member

@ljwolf ljwolf commented Jul 21, 2018

This swaps to a serialized types.SimpleNamespace, rather than a pickle to compare tests against.

This is necessary for a few reasons.
First, when you pickle your object, python will execute its methods in the new context you're testing in. This means that its references to mgwr are what you're trying to test. So, when you run stuff like MGWR.local_multicollinearity(), it's running in the current, under testing mgwr package, not the cached result from a previous known-good mgwr run.
Second, unpickling the mgwr object requires that mgwr be installed. This assumption isn't tenable for downstream packaging in pysal.

What I've done is unpack the object using its __dict__ attribute and stuff it all inside of a types.SimpleNamespace. This is kind of like a dict with dot access, so I can write it out with whatever we need. And, it only depends on the standard library and numpy to initialize, not the mgwr package.

To make this happen, though, you actually have to run some methods in order to cache their results. I've done this, and stored their results in the SimpleNamespace. Now our comparisons compare the result.method() to the cached result of method().

@ljwolf ljwolf requested a review from TaylorOshan July 21, 2018 05:09
@ljwolf ljwolf changed the title Swap to use more fundamental types than pickles Swap to use more portable types than pickles Jul 21, 2018
@TaylorOshan
Copy link
Collaborator

This makes a lot of sense, looks good to me.

@TaylorOshan TaylorOshan merged commit d4cbe53 into pysal:master Jul 23, 2018
Copy link
Collaborator

@TaylorOshan TaylorOshan left a comment

Choose a reason for hiding this comment

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

looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants