Skip to content

Commit

Permalink
Fix error message for boolean operator on symbols (#3765)
Browse files Browse the repository at this point in the history
* Fix error message for boolean operator on symbols

* style: pre-commit fixes

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Arjun <[email protected]>
  • Loading branch information
3 people authored Jan 25, 2024
1 parent 00916f3 commit a3a3746
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pybamm/expression_tree/symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,16 @@ def __mod__(self, other):
return pybamm.simplify_if_constant(pybamm.Modulo(self, other))

def __bool__(self):
raise NotImplementedError("Boolean operator not defined for Symbols.")
raise NotImplementedError(
"Boolean operator not defined for Symbols. You might be seeing this message because you are trying to "
"specify an if statement based on the value of a symbol, e.g."
"\nif x < 0:\n"
"\ty = 1\n"
"else:\n"
"\ty = 2\n"
"In this case, use heaviside functions instead:"
"\ny = 1 * (x < 0) + 2 * (x >= 0)"
)

def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
"""
Expand Down

0 comments on commit a3a3746

Please sign in to comment.