@@ -58,8 +58,6 @@ def __init__(self, variable_names, coefs, constants=None):
5858 raise ValueError ("must have at least one row in constraint matrix" )
5959 if self .coefs .shape [0 ] != self .constants .shape [0 ]:
6060 raise ValueError ("shape mismatch between coefs and constants" )
61- if np .any (np .all (self .coefs == 0 , axis = 1 )):
62- raise ValueError ("can't test a constant constraint" )
6361
6462 __repr__ = repr_pretty_delegate
6563 def _repr_pretty_ (self , p , cycle ):
@@ -102,12 +100,19 @@ def test_LinearConstraint():
102100 assert lc .coefs .dtype == np .dtype (float )
103101 assert lc .constants .dtype == np .dtype (float )
104102
103+
104+ # statsmodels wants to be able to create degenerate constraints like this,
105+ # see:
106+ # https://github.com/pydata/patsy/issues/89
107+ # We used to forbid it, but I guess it's harmless, so why not.
108+ lc = LinearConstraint (["a" ], [[0 ]])
109+ assert_equal (lc .coefs , [[0 ]])
110+
105111 from nose .tools import assert_raises
106112 assert_raises (ValueError , LinearConstraint , ["a" ], [[1 , 2 ]])
107113 assert_raises (ValueError , LinearConstraint , ["a" ], [[[1 ]]])
108114 assert_raises (ValueError , LinearConstraint , ["a" ], [[1 , 2 ]], [3 , 4 ])
109115 assert_raises (ValueError , LinearConstraint , ["a" , "b" ], [[1 , 2 ]], [3 , 4 ])
110- assert_raises (ValueError , LinearConstraint , ["a" ], [[0 ]])
111116 assert_raises (ValueError , LinearConstraint , ["a" ], [[1 ]], [[]])
112117 assert_raises (ValueError , LinearConstraint , ["a" , "b" ], [])
113118 assert_raises (ValueError , LinearConstraint , ["a" , "b" ],
0 commit comments