Skip to content

Commit

Permalink
Fix casting Formula objects to strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewwardrop committed Sep 10, 2022
1 parent 691ce3f commit 9459ac2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion formulaic/formula.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def __getitem__(self, key):
return Formula.from_spec(subformula)
return subformula

def __repr__(self): # pylint: disable=signature-differs
def __repr__(self, to_str: bool = False):
if not self._has_structure and self._has_root:
return " + ".join([str(t) for t in self])
return str(self._map(lambda terms: " + ".join([str(t) for t in terms])))
2 changes: 2 additions & 0 deletions tests/test_formula.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ def test_repr(self, formula_expr, formula_exprs):
assert repr(Formula("a | b")) == (
"root:\n [0]:\n 1 + a\n [1]:\n 1 + b"
)
assert str(formula_expr) == "1 + a + b + c + a:b + a:c + b:c + a:b:c"
assert str(formula_exprs) == ".lhs:\n a\n.rhs:\n 1 + b"

def test_equality(self):
assert Formula("a + b") == Formula("a+b")
Expand Down

0 comments on commit 9459ac2

Please sign in to comment.