Cab Maddux
08/09/2021, 8:52 PMprefect.core.task
understandably does not override __eq__
__neq__
methods to be able to suppoort task comparisons as explained in is_equal
method docstring: https://github.com/PrefectHQ/prefect/blob/1959eecf1bbbb8e3b194b288c197a6108deb8693/src/prefect/core/task.py#L924-L938
Just to confirm, this would be an appropriate way to resolve task result equality within a flow, right?
with Flow('my-flow') as flow:
task_a = get_task_a_result()
task_a_is_value = task_a.is_equal('value')
Cab Maddux
08/09/2021, 8:57 PMtask_a_is_value
to False
with Flow('my-flow') as flow:
task_a = get_task_a_result()
task_a_is_value = task_a == 'value'
If not already documented somewhere else, it might be nice to have clarification in Operators docs that a few operators are not overridden when inlines (didn't look at whether there are any others that couldn't be overridden outside of __eq__
__neq__
Kevin Kho
Cab Maddux
08/09/2021, 9:02 PMprefect.core.task.Task.is_equal
method docstring to be the correct usage as I can tell):
with Flow('my-flow') as flow:
task_a = get_task_a_result()
task_a_is_value = task_a.is_equal('value')
This does not work:
with Flow('my-flow') as flow:
task_a = get_task_a_result()
task_a_is_value = task_a == 'value'
Although was a bit confusing as other operators (+
, -
etc.) magic methods are overriddenCab Maddux
08/09/2021, 9:07 PMTask.is_equal(...)
2. If so, note that may be useful to update Operator Tasks
docs (so others don't haven't to go into the source to sort out)Kevin Kho
case
task like an if-else, so that checks for equality.Kevin Kho
Kevin Kho
is_equal
. That is correct usage.Mehdi Nazari
08/09/2021, 10:13 PMis_equal
to check on length of a python list? (this is output of a task in a flow)Kevin Kho
with Flow("test") as flow:
a = abc(1)
b = task(lambda x: len(x) == 3)(a)
because is_equal
is just value comparisonMehdi Nazari
08/09/2021, 10:20 PMCab Maddux
08/09/2021, 11:25 PM