fabian wolfmann
10/22/2020, 9:40 PM@task
def get_dict():
new_dict = {0:"hi", 1:"yes", 2:"no"}
return new_dict
@task
def print_nice_dict(elem):
print(elem)
with Flow("testing") as f:
print_nice_dict.map(get_dict)
[2020-10-22 21:42:45] ERROR - prefect.FlowRunner | Unexpected error: KeyError(3)
Traceback (most recent call last):
File "/home/fabian/anaconda3/lib/python3.7/site-packages/prefect/engine/runner.py", line 48, in inner
new_state = method(self, state, *args, **kwargs)
File "/home/fabian/anaconda3/lib/python3.7/site-packages/prefect/engine/flow_runner.py", line 530, in get_flow_run_state
executor=executor,
File "/home/fabian/anaconda3/lib/python3.7/site-packages/prefect/utilities/executors.py", line 521, in prepare_upstream_states_for_mapping
upstream_state.result[i]
KeyError: 3
[2020-10-22 21:42:45] ERROR - prefect.testing | Unexpected error occured in FlowRunner: KeyError(3)
<Failed: "Unexpected error: KeyError(3)">
Mitchell Bregman
10/22/2020, 10:13 PMwith Flow("testing") as f:
my_dict = get_dict()
print_nice_dict.map(my_dict.items())
fabian wolfmann
10/22/2020, 10:22 PMJeremiah
list(my_dict.items())
? Any indexable iterable should work - but for best results you may want to ensure it is stably sorted.fabian wolfmann
10/22/2020, 11:04 PMAttributeError: 'FunctionTask' object has no attribute items.
Jeremiah
get_dict()
task - instead of new_dict
return list(new_dict().items())
. Then you should be able to map over that directly.my_dict
was the result of a task
mI didn’t realizefabian wolfmann
10/22/2020, 11:09 PMJeremiah
fabian wolfmann
10/22/2020, 11:14 PMlist
is more stably sorted than a dict
?Jeremiah
dict
is sorted by convention in Python 3.6+, but you can’t, for example, get the 2nd element by accessing it with [2]
, it can only be accessed by key.