Skip to content

Commit

Permalink
Check that a builder roundtrips through pickle and will give the same…
Browse files Browse the repository at this point in the history
… results afterwards.
  • Loading branch information
chrish42 committed Jun 19, 2015
1 parent f6bc17a commit 4d428a2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions patsy/test_highlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Exhaustive end-to-end tests of the top-level API.

import sys
from six.moves import cPickle as pickle
import __future__
import numpy as np
from nose.tools import assert_raises
Expand Down Expand Up @@ -743,3 +744,17 @@ def test_C_and_pandas_categorical():
[[1, 0],
[1, 1],
[1, 0]])

def test_pickle_builder_roundtrips():
design_matrix = dmatrix("x + a", {"x": [1, 2, 3],
"a": ["a1", "a2", "a3"]})
builder = design_matrix.design_info.builder

new_data = {"x": [10, 20, 30],
"a": ["a3", "a1", "a2"]}
m1 = dmatrix(builder, new_data)

builder2 = pickle.loads(pickle.dumps(design_matrix.design_info.builder))
m2 = dmatrix(builder2, new_data)

assert np.allclose(m1, m2)

0 comments on commit 4d428a2

Please sign in to comment.