Skip to content

Commit ad6edb5

Browse files
committed
fixed bug with ImplicitSeries evaluation of boolean expressions containing Abs
1 parent 3ea0c9c commit ad6edb5

4 files changed

Lines changed: 73 additions & 2 deletions

File tree

doc/source/changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
Changelog
33
==========
44

5+
v3.4.4
6+
======
7+
8+
* Fixed bug with `ImplicitSeries`'s evaluation of boolean expressions.
9+
10+
511
v3.4.3
612
======
713

spb/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.4.3"
1+
__version__ = "3.4.4"

spb/series.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2258,7 +2258,10 @@ def expr(self, expr):
22582258
stacklevel=1)
22592259

22602260
if isinstance(expr, BooleanFunction):
2261-
self._non_adaptive_expr = None
2261+
# NOTE: at this stage, I'll be using the adaptive algorithm.
2262+
# However, I need to set the expression for the uniform meshing
2263+
# algorithm too, in case the adaptive algorithm fails to evaluate.
2264+
self._non_adaptive_expr = expr
22622265
self._is_equality = False
22632266
else:
22642267
# these are needed for uniform meshing evaluation

tests/test_series.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4564,3 +4564,65 @@ def test_params_multi_value_widgets_1():
45644564
new_params = {(a, b): (-3, 4), c: 2}
45654565
s.params = new_params
45664566
assert s.params == {a: -3, b: 4, c: 2}
4567+
4568+
4569+
def test_implicit_2d_series_boolean_and():
4570+
x, y = symbols("x, y")
4571+
4572+
cond1 = y + 2*Abs(x) > 0
4573+
cond2 = x > 0
4574+
cond3 = y < 0
4575+
4576+
s1 = ImplicitSeries(cond1, (x, -5, 5), (y, -10, 10), adaptive=False)
4577+
assert s1.adaptive is False
4578+
s1.get_data()
4579+
assert s1.adaptive is False
4580+
4581+
s2 = ImplicitSeries(cond1, (x, -5, 5), (y, -10, 10), adaptive=True)
4582+
assert s2.adaptive is True
4583+
# because of Abs, the adaptive algorithm is going to fail, so the uniform
4584+
# meshing algorithm takes over
4585+
with warns(
4586+
UserWarning,
4587+
match="Adaptive meshing could not be applied to the expression. Using uniform meshing."
4588+
):
4589+
s2.get_data()
4590+
assert s2.adaptive is False
4591+
4592+
s3 = ImplicitSeries(cond2, (x, -5, 5), (y, -10, 10), adaptive=False)
4593+
assert s3.adaptive is False
4594+
s3.get_data()
4595+
assert s3.adaptive is False
4596+
4597+
s4 = ImplicitSeries(cond2, (x, -5, 5), (y, -10, 10), adaptive=True)
4598+
assert s4.adaptive is True
4599+
s4.get_data()
4600+
assert s4.adaptive is True
4601+
4602+
with warns(
4603+
UserWarning,
4604+
match="The provided expression contains Boolean functions."
4605+
):
4606+
# Because of boolean And, the adaptive algorithm takes over
4607+
s5 = ImplicitSeries(
4608+
cond2 & cond3, (x, -5, 5), (y, -10, 10), adaptive=False)
4609+
assert s5.adaptive is True
4610+
s5.get_data()
4611+
assert s5.adaptive is True
4612+
4613+
s6 = ImplicitSeries(cond2 & cond3, (x, -5, 5), (y, -10, 10), adaptive=True)
4614+
assert s6.adaptive is True
4615+
s6.get_data()
4616+
assert s6.adaptive is True
4617+
4618+
s7 = ImplicitSeries(cond1 & cond2, (x, -5, 5), (y, -10, 10), adaptive=True)
4619+
assert s7.adaptive is True
4620+
# because of Abs, the adaptive algorithm is going to fail, so the uniform
4621+
# meshing algorithm takes over
4622+
with warns(
4623+
UserWarning,
4624+
match="Adaptive meshing could not be applied to the expression. Using uniform meshing."
4625+
):
4626+
s7.get_data()
4627+
assert s7.adaptive is False
4628+

0 commit comments

Comments
 (0)