Swap to use more portable types than pickles #23
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This swaps to a serialized
types.SimpleNamespace
, rather than apickle
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 likeMGWR.local_multicollinearity()
, it's running in the current, under testingmgwr
package, not the cached result from a previous known-goodmgwr
run.Second, unpickling the
mgwr
object requires thatmgwr
be installed. This assumption isn't tenable for downstream packaging inpysal
.What I've done is unpack the object using its
__dict__
attribute and stuff it all inside of atypes.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 themgwr
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 theresult.method()
to the cached result ofmethod()
.