Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/pydata/patsy
Browse files Browse the repository at this point in the history
  • Loading branch information
njsmith committed Oct 26, 2016
2 parents 62c13c2 + e877b74 commit 6aa78e7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions patsy/constraint.py
Expand Up @@ -58,8 +58,6 @@ def __init__(self, variable_names, coefs, constants=None):
raise ValueError("must have at least one row in constraint matrix")
if self.coefs.shape[0] != self.constants.shape[0]:
raise ValueError("shape mismatch between coefs and constants")
if np.any(np.all(self.coefs == 0, axis=1)):
raise ValueError("can't test a constant constraint")

__repr__ = repr_pretty_delegate
def _repr_pretty_(self, p, cycle):
Expand Down Expand Up @@ -102,12 +100,19 @@ def test_LinearConstraint():
assert lc.coefs.dtype == np.dtype(float)
assert lc.constants.dtype == np.dtype(float)


# statsmodels wants to be able to create degenerate constraints like this,
# see:
# https://github.com/pydata/patsy/issues/89
# We used to forbid it, but I guess it's harmless, so why not.
lc = LinearConstraint(["a"], [[0]])
assert_equal(lc.coefs, [[0]])

from nose.tools import assert_raises
assert_raises(ValueError, LinearConstraint, ["a"], [[1, 2]])
assert_raises(ValueError, LinearConstraint, ["a"], [[[1]]])
assert_raises(ValueError, LinearConstraint, ["a"], [[1, 2]], [3, 4])
assert_raises(ValueError, LinearConstraint, ["a", "b"], [[1, 2]], [3, 4])
assert_raises(ValueError, LinearConstraint, ["a"], [[0]])
assert_raises(ValueError, LinearConstraint, ["a"], [[1]], [[]])
assert_raises(ValueError, LinearConstraint, ["a", "b"], [])
assert_raises(ValueError, LinearConstraint, ["a", "b"],
Expand Down

0 comments on commit 6aa78e7

Please sign in to comment.