1515import numpy as np
1616from patsy import PatsyError
1717from patsy .compat import triu_indices , tril_indices , diag_indices
18- from patsy .util import repr_pretty_delegate , repr_pretty_impl , safe_issubdtype
18+ from patsy .util import (repr_pretty_delegate , repr_pretty_impl ,
19+ safe_issubdtype ,
20+ no_pickling , assert_no_pickling )
1921
2022class ContrastMatrix (object ):
2123 """A simple container for a matrix used for coding categorical factors.
@@ -46,6 +48,8 @@ def __init__(self, matrix, column_suffixes):
4648 def _repr_pretty_ (self , p , cycle ):
4749 repr_pretty_impl (p , self , [self .matrix , self .column_suffixes ])
4850
51+ __getstate__ = no_pickling
52+
4953def test_ContrastMatrix ():
5054 cm = ContrastMatrix ([[1 , 0 ], [0 , 1 ]], ["a" , "b" ])
5155 assert np .array_equal (cm .matrix , np .eye (2 ))
@@ -56,6 +60,8 @@ def test_ContrastMatrix():
5660 from nose .tools import assert_raises
5761 assert_raises (PatsyError , ContrastMatrix , [[1 ], [0 ]], ["a" , "b" ])
5862
63+ assert_no_pickling (cm )
64+
5965# This always produces an object of the type that Python calls 'str' (whether
6066# that be a Python 2 string-of-bytes or a Python 3 string-of-unicode). It does
6167# *not* make any particular guarantees about being reversible or having other
@@ -176,6 +182,8 @@ def code_without_intercept(self, levels):
176182 names = _name_levels ("T." , levels [:reference ] + levels [reference + 1 :])
177183 return ContrastMatrix (contrasts , names )
178184
185+ __getstate__ = no_pickling
186+
179187def test_Treatment ():
180188 t1 = Treatment ()
181189 matrix = t1 .code_with_intercept (["a" , "b" , "c" ])
@@ -272,6 +280,8 @@ def code_with_intercept(self, levels):
272280 def code_without_intercept (self , levels ):
273281 return self ._code_either (False , levels )
274282
283+ __getstate__ = no_pickling
284+
275285def test_Poly ():
276286 t1 = Poly ()
277287 matrix = t1 .code_with_intercept (["a" , "b" , "c" ])
@@ -378,6 +388,8 @@ def code_without_intercept(self, levels):
378388 included_levels = levels [:omit_i ] + levels [omit_i + 1 :]
379389 return ContrastMatrix (matrix , _name_levels ("S." , included_levels ))
380390
391+ __getstate__ = no_pickling
392+
381393def test_Sum ():
382394 t1 = Sum ()
383395 matrix = t1 .code_with_intercept (["a" , "b" , "c" ])
@@ -471,6 +483,8 @@ def code_without_intercept(self, levels):
471483 return ContrastMatrix (contrast ,
472484 _name_levels ("H." , levels [1 :]))
473485
486+ __getstate__ = no_pickling
487+
474488def test_Helmert ():
475489 t1 = Helmert ()
476490 for levels in (["a" , "b" , "c" , "d" ], ("a" , "b" , "c" , "d" )):
@@ -536,6 +550,8 @@ def code_without_intercept(self, levels):
536550 contrast = self ._diff_contrast (levels )
537551 return ContrastMatrix (contrast , _name_levels ("D." , levels [:- 1 ]))
538552
553+ __getstate__ = no_pickling
554+
539555def test_diff ():
540556 t1 = Diff ()
541557 matrix = t1 .code_with_intercept (["a" , "b" , "c" , "d" ])
0 commit comments