Skip to content

Commit

Permalink
fix: remove numpy dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Lundez committed Oct 9, 2023
1 parent 26e98f5 commit b81d45e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions solara/components/slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import ipyvue
import ipyvuetify
import numpy as np
import reacton.core
import traitlets
from typing_extensions import Literal
Expand Down Expand Up @@ -425,7 +424,12 @@ def _produce_tick_labels(tick_labels: Union[List[str], Literal["end_points"], bo
elif tick_labels is False:
_tick_labels = None
elif tick_labels is True:
_tick_labels = list(map(str, np.arange(min, max, step=step)))
_tick_labels, start = [], min

while start < max:
_tick_labels.append(str(start))
start += step
_tick_labels.append(str(max))
else:
_tick_labels = tick_labels

Expand Down
4 changes: 3 additions & 1 deletion tests/unit/slider_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ def get_tick_labels(clazz, min, max, step, **kwargs) -> list:
def test_int_slider():
reference_ticks = [3, 4, 5]
assert get_tick_labels(solara.IntSlider, 3, 5, 1, tick_labels="end_points") == ["3", "", "5"]
assert get_tick_labels(solara.IntSlider, 3, 5, 1, tick_labels=True) == ["3", "4", "5"]
assert get_tick_labels(solara.IntSlider, 3, 5, 1) is None
assert get_tick_labels(solara.IntSlider, 3, 5, 1, tick_labels=reference_ticks) == reference_ticks


def test_float_slider():
reference_ticks = [3, 3.5, 4, 4.5, 5]
reference_ticks = [3.0, 3.5, 4.0, 4.5, 5.0]
middle_empty_str = [""] * (len(reference_ticks) - 2)
assert get_tick_labels(solara.FloatSlider, 3, 5, 0.5, tick_labels="end_points") == ["3", *middle_empty_str, "5"]
assert list(map(float, get_tick_labels(solara.FloatSlider, 3, 5, 0.5, tick_labels=True))) == reference_ticks
assert get_tick_labels(solara.FloatSlider, 3, 5, 0.5) is None
assert get_tick_labels(solara.FloatSlider, 3, 5, 0.5, tick_labels=reference_ticks) == reference_ticks

Expand Down

0 comments on commit b81d45e

Please sign in to comment.