Skip to content

Commit 4d428a2

Browse files
committed
Check that a builder roundtrips through pickle and will give the same results afterwards.
1 parent f6bc17a commit 4d428a2

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
@@ -743,3 +744,17 @@ def test_C_and_pandas_categorical():
743744
[[1, 0],
744745
[1, 1],
745746
[1, 0]])
747+
748+
def test_pickle_builder_roundtrips():
749+
design_matrix = dmatrix("x + a", {"x": [1, 2, 3],
750+
"a": ["a1", "a2", "a3"]})
751+
builder = design_matrix.design_info.builder
752+
753+
new_data = {"x": [10, 20, 30],
754+
"a": ["a3", "a1", "a2"]}
755+
m1 = dmatrix(builder, new_data)
756+
757+
builder2 = pickle.loads(pickle.dumps(design_matrix.design_info.builder))
758+
m2 = dmatrix(builder2, new_data)
759+
760+
assert np.allclose(m1, m2)

0 commit comments

Comments
 (0)