https://prefect.io logo
#prefect-community
Title
# prefect-community
r

Romain

04/29/2021, 9:21 AM
Hello team, Is there a bug in "apply_map" working with flatten? I tried to modify the example from the doc (https://docs.prefect.io/core/concepts/mapping.html#flat-mapping) to use apply_map:
Copy code
from prefect import Flow, task, flatten, apply_map
@task
def A():
    return [1, 2, 3]

@task
def B(x):
    return list(range(x))

@task
def C(y):
    return y + 100
    
def foo(y):
    return C(y)

with Flow('flat map') as f:
    a = A() # [1, 2, 3]
    b = B.map(x=a) # [[0], [0, 1], [0, 1, 2]]
    c = apply_map(foo, y=flatten(b)) # [100, 100, 101, 100, 101, 102]
While running it, I get : "TypeError: can only concatenate list (not "int") to list" Am I missing something?
z

Zach Angell

04/29/2021, 1:47 PM
Hi @Romain! Thanks for writing this up. This could be a bug, I'm digging a bit deeper into it. In the meantime, I'm happy to help with any workarounds if this is a blocker.
👍 1
r

Romain

04/29/2021, 1:48 PM
Hi @Zach Angell as a workaround I m using a FunctionTask to flatten my lists.
👍 1
z

Zach Angell

04/29/2021, 1:54 PM
@Marvin open "apply_map does not flatten arguments correctly"
m
2 Views