Why does increment round value?

Why does numeric increment on a panel result in a rounded value?

Consider the following:

import param as pm
import panel as pn
pn.extension() 

class A(pm.Parameterized):
    a = pm.Number(0.3, step=1)

a = A()

pn.panel(a)

Clicking the GUI to increment up results in 1 instead of 1.3. Then clicking to decrement results in 0 instead of bring back to the original input of 0.3. I would like to be able to return to a default value by incrementing then decrementing.

Hi @LinuxIsCool,

Miss read this, now I understand I think, the step rounds to nearest int rather than increment by x.x+1 by the looks of it

This seems to do the trick using bounds in conjunction with the step, going positive,

import param as param
import panel as pn
pn.extension()

class A(pm.Parameterized):
    a = param.Number(0.3, bounds=(0.3,50.3),step=1)

a = A()

pn.panel(a)

when using negative numbers it literally seems to perform the step calculation around the zero point by:

-0.7, step 1, 0.3
1+(-0.7) = 0.3

Which is mathematically correct but sometimes I think the user is after something more like when implementing a step change of 1 - which I don’t know if would be correct and I imagine is more difficult to handle in code

-1.3, -0.3, 0.3, 1.3

Anyway the below doesn’t achieve the immediately above sequence but if you don’t need to go negative then the above example should be fine

import param as param
import panel as pn
pn.extension()

class A(pm.Parameterized):
    a = param.Number(0.3, bounds=(-100.7,50.3),step=1)

a = A()

pn.panel(a)

Thanks, Carl

1 Like

The output of pn.panel(a) is equivalent to pn.widgets.FloatInput(value=0.3, step=1.0), which show the same behavior.

This seems to be a Bokeh problem, I will raise an issue there.

from bokeh.io import output_notebook, show
from bokeh.layouts import column
from bokeh.models import Spinner
from bokeh.models.formatters import TickFormatter

output_notebook()

a = Spinner(value=0.3, low=0, mode="float", step=1.0000000001, format="0.0")
b = Spinner(value=0.3, low=0, mode="float", step=1, format="0.0")

show(column(a, b))

2 Likes