Skip to content

Commit 34bc09b

Browse files
committed
Check that a builder roundtrips through pickle and will give the same results afterwards.
1 parent dd6b3ba commit 34bc09b

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 six
1011
import numpy as np
@@ -758,3 +759,17 @@ def test_C_and_pandas_categorical():
758759
[[1, 0],
759760
[1, 1],
760761
[1, 0]])
762+
763+
def test_pickle_builder_roundtrips():
764+
design_matrix = dmatrix("x + a", {"x": [1, 2, 3],
765+
"a": ["a1", "a2", "a3"]})
766+
builder = design_matrix.design_info.builder
767+
768+
new_data = {"x": [10, 20, 30],
769+
"a": ["a3", "a1", "a2"]}
770+
m1 = dmatrix(builder, new_data)
771+
772+
builder2 = pickle.loads(pickle.dumps(design_matrix.design_info.builder))
773+
m2 = dmatrix(builder2, new_data)
774+
775+
assert np.allclose(m1, m2)

0 commit comments

Comments
 (0)