Hello,
Given this example:
import pandas as pd
import param
df = pd.DataFrame(
{"a": [1,2,3]}
)
class A(param.Parameterized):
df = param.DataFrame(default = df)
x = param.Integer(default = 1)
def __init__(self, **params):
super().__init__(**params)
self.param.watch(fn=self.test_x, parameter_names=['x'], onlychanged=True)
self.param.watch(fn=self.test_df, parameter_names=['df'], onlychanged=True)
def set_df(self, df):
self.df = df
def set_x(self, x):
self.x = x
def test_x(self, event):
print(f"x is {event.type}")
def test_df(self, event):
# print(event.old.equals(event.new))
print(f"df is {event.type}")
a = A()
a.set_df(df)
a.set_x(1)
>>> df is changed
I was wondering why in the case of the integer, param
correctly detects that the new value set on x
is the same as the old one and so doesn’t print "x is changed"
, while re-setting df
to an identical value does trigger the watched function, even though onlychanged=True
?
I guess it has something to do with how event.old
and event.new
are being compared to each other? In the case of the dataframe I would like it to check for something like event.old.equals(event.new)
(using pandas .equals
method), but I don’t really know where to change this.
Any ideas or hints? Thanks!