Skip to content

Commit

Permalink
Fix floating point error in IntRangeSlider (#6516)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro authored Mar 18, 2024
1 parent ddedd8d commit 003e0f8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions panel/tests/chat/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def callback(contents, user, instance):

chat_interface.callback = callback
chat_interface.send("Message 1")
wait_until(lambda: len(chat_interface.objects) >= 2)
wait_until(lambda: chat_interface.objects[1].object == 1)
chat_interface._click_rerun(None)
wait_until(lambda: chat_interface.objects[1].object == 2)
Expand Down
16 changes: 16 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,18 @@ 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)

page.locator(".noUi-touch-area").nth(0).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 003e0f8

Please sign in to comment.