Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rx.when not using initial value #995

Open
MarcSkovMadsen opened this issue Dec 26, 2024 · 1 comment
Open

rx.when not using initial value #995

MarcSkovMadsen opened this issue Dec 26, 2024 · 1 comment

Comments

@MarcSkovMadsen
Copy link
Collaborator

I was trying to document rx.when on the main branch. Since there is no example in the docs about initial argument I tried to create one. But its not working as I would expect

from param import rx

def expensive_function(a, b):
    print(f'multiplying {a=} and {b=}')
    return a * b

a = rx(1)
b = rx(2)

gate = rx(False)
gated_expr = rx(expensive_function)(a, b).rx.when(gate, initial="Initial")
assert gated_expr.rx.value=="Initial"
$ python script.py
multiplying a=1 and b=2
Traceback (most recent call last):
  File "/home/jovyan/repos/private/param/script.py", line 12, in <module>
    assert gated_expr.rx.value=="Initial"
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError

I would expect this not to raise an error and for the expensive_function not to be evaluated.

@MarcSkovMadsen
Copy link
Collaborator Author

MarcSkovMadsen commented Dec 26, 2024

If the gate is a param.Event it works as expected though.

import param
from param import rx

def expensive_function(a, b):
    print(f'multiplying {a=} and {b=}')
    return a * b

a = rx(1)
b = rx(2)

class State(param.Parameterized):
    gate = param.Event()

gate = State().gate
gated_expr = rx(expensive_function)(a, b).rx.when(gate, initial="Initial")
assert gated_expr.rx.value=="Initial"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant