Fundamentals of Dask Transcripts
Chapter: Dask Delayed
Lecture: Best practices and references

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Welcome back to our Daskis and congratulations on making it through that checkpoint.
0:05 Now, I want to tell you about some best practices when using 'Dask Delayed'. Now, there are lots of best practices we could discuss.
0:12 We're going to talk about three now and it's really the handful of ones that we think are probably worth mentioning upfront based on the type of code.
0:20 We see people right all the time with Dask and Dask Delayed to the first point number one, 'Don't call Delayed on the result of a function as it will
0:29 execute immediately', 'Do Call Delayed on the function and then pass the arguments of the function to the code you've written there,
0:37 best practice two, 'compute at once instead of repeatedly'. So here we see that we're calling, compute within a for loop. Let's avoid that completely.
0:48 So what we want to do is collect as many delayed calls as possible for one
0:52 compute so we look through them here and then we pass them to 'dask.compute( )' there. Now, the third one,
0:58 this is worth spending a moment on because we've usually seen functions passed to the Delayed wrapper. Instead of doing that.
1:05 When defining a function, you can add the '@dask.delayed' decorator at the top
1:09 which pretty much does the same as passing a function to the delayed rapper. Now the best practice here is do not mutate inputs in the function,
1:20 so don't do this mutation here within the function. Okay. What the best practices is to return the new value or to return copies
1:28 Okay, so for more best practices, I'd encourage you to refer to the Dask documentation. Now to wrap up.
1:37 We have included some references below of what we think are some pretty cool documentation and
1:42 tutorials on Dask Delay. See you back here soon for the next video.


Talk Python's Mastodon Michael Kennedy's Mastodon