I had a quick question about the `.map` within pre...
# ask-community
k
I had a quick question about the
.map
within prefect. Is it guaranteed that the order is preserved across multiple maps, like a python
multiprocessing.pool.map
? Or is it not a guarantee that the order is preserved, like
multiprocessing.pool.imap_unordered
. I couldn't find whether this was guaranteed or not in the
prefect docs
.
k
Hey @Kyle Hansen, is it not guaranteed. There is no priority ordering on the map.
k
So just to make sure, if I do a
func.map([a, b, c])
the result I get back might be
[result_b, result_c, result_a]
? I know they might not finish computing in the same order, but from my small scale tests, it seems I'm getting back
[result_a, result_b, result_c]
which I'm guessing is just an odd artifact of being lucky?
k
Oh that order of results in the list is guaranteed but the order of execution is not. So if you chain mapped tasks
a = A.map()
and
B.map(a)
, the output and input will connect as expected
👍 1
k
Ah ok. Thanks for confirming that. This is kind of what I thought from my testing, but I wanted to make sure that was guaranteed. And I'm assuming that order is also preserved with a flat-mapping? So if I have
list = [[a, b, c], [d, e, f]]
and do a
func.map(flatten(list))
then my results back will be of the order
[result_a, result_b, result_c, result_d, result_e, result_f]
?
This seems to be an assumption in the
mapping
section of the documentation and subsequent examples (eg. Flat-mapping), but I couldn't find anywhere it explicitly says that is guaranteed to be true.
k
That one i’m not 100% sure. I’ll ask the team for you
🙏 1
Yes it’s guaranteed
🙏 1
k
Great. Thank you Kevin!!