Skip to content

Commit

Permalink
Fix floating point error in IntRangeSlider
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro committed Mar 18, 2024
1 parent ddedd8d commit b6999b7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions panel/tests/ui/widgets/test_sliders.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from panel.tests.util import serve_component, wait_until
from panel.widgets import (
EditableFloatSlider, EditableIntSlider, EditableRangeSlider,
IntRangeSlider,
)


Expand Down Expand Up @@ -297,3 +298,19 @@ def test_editablerangeslider_no_overlap(page):

down_end.click(click_count=3)
wait_until(lambda: widget.value == (1, 1), page)


def test_intrangeslider(page):
# Test for https://github.com/holoviz/panel/issues/6483
# Which has floating point error, e.g., 4 will return
# 3.9999999999999996, so we can't use int() in our code
# but needs to use round() instead.
widget = IntRangeSlider(start=1, end=10, step=1)
serve_component(page, widget)

slider_handle = page.locator(".noUi-touch-area").nth(0)
slider_handle.click()
for _ in range(3):
page.keyboard.press("ArrowRight")

wait_until(lambda: widget.value == (4, 10), page)
4 changes: 2 additions & 2 deletions panel/widgets/slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,10 +646,10 @@ class IntRangeSlider(RangeSlider):
def _process_property_change(self, msg):
msg = super()._process_property_change(msg)
if 'value' in msg:
msg['value'] = tuple([v if v is None else int(v)
msg['value'] = tuple([v if v is None else round(v)
for v in msg['value']])
if 'value_throttled' in msg:
msg['value_throttled'] = tuple([v if v is None else int(v)
msg['value_throttled'] = tuple([v if v is None else round(v)
for v in msg['value_throttled']])
return msg

Expand Down

0 comments on commit b6999b7

Please sign in to comment.