Fixtures के साथ data pipeline का unit testing
आपने पिछले वीडियो में सीखा कि unit testing आपकी data pipeline पर अधिक भरोसा करने में मदद करती है, और डेवलपमेंट के दौरान बग्स पकड़ने में भी सहायक होती है। इस अभ्यास में, आप pytest लाइब्रेरी और assert का उपयोग करके fixtures और unit tests दोनों लिखने का अभ्यास करेंगे।
जिस transform फंक्शन के आसपास आप unit tests बनाएँगे, वह संदर्भ के लिए नीचे दिया गया है। pandas को pd नाम से इम्पोर्ट किया गया है, और pytest() लाइब्रेरी लोड होकर उपयोग के लिए तैयार है।
def transform(raw_data):
raw_data["tax_rate"] = raw_data["total_taxes_paid"] / raw_data["total_taxable_income"]
raw_data.set_index("industry_name", inplace=True)
return raw_data
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में ETL और ELT
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Define a pytest fixture
@pytest.fixture()
____ ____():
raw_data = pd.read_csv("raw_tax_data.csv")
# Transform the raw_data, store in clean_data DataFrame, and return the variable
clean_data = ____
return ____