I'm currently looking at how map_task works and <f...
# flyte-support
c
I'm currently looking at how map_task works and followed the example here, however if I add a second parameter to the
detect_anomalies
task, I get the error:
Copy code
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 🧵
Copy code
import 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)
p
I think this is best shown in the legacy documentation here: https://docs-legacy.flyte.org/en/latest/user_guide/advanced_composition/map_tasks.html#map-a-task-with-multiple-inputs The
map_task
only wants to step through a single list, you have to bind the static values first
so you'd end up with something like
Copy code
partial_task = functools.partial(detect_anomalies, threshold=11)
map_task(partial_task)(data_point=data)
c
Superb! Thank you very much @proud-glass-36655, especially for the explanation. Now that docs are public I'll open an MR so that this legacy documentation gets surfaced as it clearly still applies.
p
No problem, glad to help!