crooked-holiday-38139
05/23/2025, 4:02 PMdetect_anomalies
task, I get the error:
TypeTransformerFailedError: Failed to Bind variable 'threshold' for function
'map_task.map_detect_anomalies_6b3bd0353da5de6e84d7982921ead2b3-arraynode':
Expected a list
Could someone explain why this error gets thrown?
Code snippet in 🧵crooked-holiday-38139
05/23/2025, 4:03 PMimport logging
from flytekit import task, workflow, map_task
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
@task
def detect_anomalies(data_point: int, threshold: int) -> bool:
return data_point > threshold
@task
def coalesce(evals: List[bool]) -> None:
<http://logger.info|logger.info>('Result: {}'.format(evals))
@workflow
def map_workflow(data: list[int] = [10, 12, 11, 10, 13, 12, 100, 11, 12, 10]) -> None:
# Use the map task to apply the anomaly detection function to each data point
mapped_tasks = map_task(detect_anomalies)(data_point=data, threshold=11)
return coalesce(mapped_tasks)
proud-glass-36655
05/23/2025, 4:45 PMmap_task
only wants to step through a single list, you have to bind the static values firstproud-glass-36655
05/23/2025, 4:46 PMpartial_task = functools.partial(detect_anomalies, threshold=11)
map_task(partial_task)(data_point=data)
crooked-holiday-38139
05/23/2025, 6:29 PMproud-glass-36655
05/23/2025, 6:30 PM