Skip to content

Commit c9e91fc

Browse files
committed
Check that a builder roundtrips through pickle and will give the same results afterwards.
1 parent 3819ae9 commit c9e91fc

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

patsy/test_highlevel.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Exhaustive end-to-end tests of the top-level API.
66

77
import sys
8+
from six.moves import cPickle as pickle
89
import __future__
910
import numpy as np
1011
from nose.tools import assert_raises
@@ -744,3 +745,17 @@ def test_C_and_pandas_categorical():
744745
[[1, 0],
745746
[1, 1],
746747
[1, 0]])
748+
749+
def test_pickle_builder_roundtrips():
750+
design_matrix = dmatrix("x + a", {"x": [1, 2, 3],
751+
"a": ["a1", "a2", "a3"]})
752+
builder = design_matrix.design_info.builder
753+
754+
new_data = {"x": [10, 20, 30],
755+
"a": ["a3", "a1", "a2"]}
756+
m1 = dmatrix(builder, new_data)
757+
758+
builder2 = pickle.loads(pickle.dumps(design_matrix.design_info.builder))
759+
m2 = dmatrix(builder2, new_data)
760+
761+
assert np.allclose(m1, m2)

0 commit comments

Comments
 (0)