holoviz / param

Param: Make your Python code clearer and more reliable by declaring Parameters
https://param.holoviz.org
BSD 3-Clause "New" or "Revised" License
412 stars 69 forks source link

Define Comparator equality functions for more types #902

Open philippjfr opened 5 months ago

philippjfr commented 5 months ago

The Comparator in Param is used to check if a Parameter value has changed and therefore needs to trigger all watchers to inform them of this change. The Comparator was designed to be extended to support different object types and should cover at least the basic types that Param supports. There is also a tradeoff though, if a comparison is more expensive than the computations that could be triggered by the parameter value change then it's not worth it. For that reason we initially did not implement comparisons for things like arrays, however we should consider implementing some kind of size based cut-off where the comparator just gives up.

Here's a list of objects that we should definitely implement comparisons for:

and here's some objects that we should at least consider:

There's probably many I've missed.

bertcoerver commented 4 months ago

Hi, for my own purposes I added a "custom" equality function for pd.Dataframe like this:

import param.parameterized
param.parameterized.Comparator.equalities.update(
    {pd.DataFrame: lambda obj1, obj2: obj1.equals(obj2)}
    )

More info here: https://discourse.holoviz.org/t/param-watch-and-onlychanged-true-unexpected-behaviour-on-param-dataframe/6871