न्यूमेरिक रेंज जाँचना
स्ट्रीमिंग स्टार्टअप के मूवी डेटासेट पर वापस चलते हैं. vote_count और budget को छोटे dtypes में डाउनकास्ट करने से पहले, उनके अधिकतम मान जाँचिए और उन्हें छोटे integer टाइप्स की upper bound से तुलना कीजिए. इससे पता चलेगा कि 32-bit (या 16-bit) सुरक्षित है या नहीं.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Polars के साथ Data Pipelines का स्केलिंग और ऑप्टिमाइज़ेशन
अभ्यास निर्देश
vote_countऔरbudgetका max निकालिए.budgetकेInt32औरInt16वर्ज़न की upper bound दिखाइए.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
result = movies.select(
# Largest vote_count
pl.col("vote_count").____().alias("vote_count_max"),
# Largest budget
pl.col("budget").____().alias("budget_max"),
# Upper bounds of smaller dtypes
pl.col("budget").cast(pl.Int32).____().alias("budget_int32_upper"),
pl.col("budget").cast(pl.Int16).____().alias("budget_int16_upper"),
)
print(result)