Eager evaluation computes an expression when it is specified, producing results immediately rather than deferring work until those results are needed. Pandas and NumPy use this model, while Dask constructs a task graph and computes later. section 10.1.2
Eager execution trades simplicity and repeated access against memory use and unnecessary work:
- Materializes all results at once, so a list can consume substantially more memory than a generator processing values one at a time. section 2.5.1
- Computes results that may never be consumed; a lazy computation can stop after finding a single qualifying value. section 2.5.1
- Makes repeated traversal useful when computation is inexpensive and the materialized representation fits in memory. section 2.5.1
- Requires measurement rather than assumption: constructing list(range(1000000)) took far longer than creating range(1000000) in the demonstrated benchmark. section 2.2.3
Eagerly materializing a generator
A generator can stream file temperatures with yield, retaining only the current value during iteration. Converting it with temperatures = list(temperatures) eagerly computes and stores the sequence, which helps repeated visits when its memory cost is acceptable. section 2.5.1
import numpy as np
import dask.dataframe as dd #1
taxes = dd.read_csv("FY2016-STC-Category-Table.csv", sep="\t")
taxes["Amount"] = taxes["Amount"].str.replace(",",
"").replace("X", np.nan).astype(float)
taxes["Tax_Type"] = taxes["Tax_Type"].astype(
"category").cat.as_known() #2
pivot = taxes.pivot_table(index="Geo_Name",
columns="Tax_Type", values="Amount")
has_property_info = pivot[
~pivot["Property Taxes"].isna()].index #3
pivot_clean = pivot.loc[has_property_info]
frac_property = pivot_clean["Property Taxes"] / pivot_clean["Total Taxes"]
A Dask data-processing pipeline makes the execution boundary visible: transformations build a task graph, and compute() triggers the result. section 10.1.2




