Skip to content

Weird behavior when working with numpy #289

Open
@ShannonZ

Description

@ShannonZ

Except for attribute bindings of UI elements that do not require the use of to_value, is it necessary to add to_value in all other places where fields are used?

from ex4nicegui import rxui,to_value
from nicegui import ui
import numpy as np

class BalanceParameter(rxui.ViewModel):
    GAstart:float = 0.0
    GAend:float = 50.0
    NG:int = 8
    GAList = []
    BAList = []
    
    def __init__(self):
        super().__init__()
        self.update_GAList()
    
    def update_GAList(self):
        print('update')
        self.GAList = np.linspace(to_value(self.GAstart),to_value(self.GAend),to_value(self.NG),endpoint=True).tolist()
        self.BAList = np.linspace(self.GAstart,self.GAend,self.NG,endpoint=True).tolist()
        print(to_value(self.GAList)) # works as expected
        print(to_value(self.BAList))  # lost the last element 
        print(self.BAList)                 # empty
p = BalanceParameter()
ui.button('Play')

rxui.number(value=p.NG,format='%d',min=1,max=100,suffix='ttt').props('standout label-color="blue" ').style('width:160px')
ui.run(port=8088)

The output:

update
[0.0, 7.142857142857143, 14.285714285714286, 21.42857142857143, 28.571428571428573, 35.714285714285715, 42.85714285714286, 50.0]
[0.0, 7.142857142857143, 14.285714285714286, 21.42857142857143, 28.571428571428573, 35.714285714285715, 42.85714285714286, <ex4nicegui.utils
.proxy.float.FloatProxy object at 0x0000027D2F226360>]
[]
NiceGUI ready to go on http://localhost:8088, http://172.16.10.175:8088, and http://192.168.0.9:8088

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions