0Pricing
MLOps Academy · درس

اختبار مسار البيانات اختباراً وحدياً

تحقّق باستخدام pytest من الأشكال والأنواع والنطاقات.

اختبار مسار البيانات اختباراً وحدياً درس مجاني في MLOps Academy على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في MLOps Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة MLOps Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Test the Data, Not Just the Model

Most ML bugs hide in the data pipeline, not the model. A few cheap unit tests on your data catch problems long before training. 🧪

What pytest Gives You

You write tests as plain functions and let pytest discover and run them. Any assert that fails turns into a clear, readable failure report.

Anatomy of a Data Test

A data test loads a sample, calls your transform, then asserts an expectation. The key tool is the assert statement deciding pass or fail.

def test_no_nulls(df):
    assert df["age"].notna().all()

Assert the Shape

Pipelines silently drop or add columns. Lock the shape so a 10-column frame never sneaks through as 9 columns unnoticed.

def test_shape(df):
    assert df.shape[1] == 10

Assert the Column Types

A number read as text breaks training quietly. Pin each column dtype so a type drift fails the test instead of the model.

def test_dtype(df):
    assert df["price"].dtype == "float64"

Assert Sensible Ranges

Guard against impossible values. A range check stops a negative age or a 300% probability from ever reaching your model.

def test_range(df):
    assert df["age"].between(0, 120).all()

Catch the Nulls

Missing values are the most common data bug. Assert that critical columns have no nulls, or that nulls stay under a known threshold.

Use Small Fixtures

Tests should run in milliseconds. A pytest fixture builds a tiny hand-made frame so tests stay fast and never touch real data.

import pytest
@pytest.fixture
def df():
    return load_sample()

Test Each Transform Alone

Test one step at a time so failures point to the exact culprit. This is unit testing: small, isolated, and fast to debug.

Run the Suite

One command runs every test and prints a green or red summary. Run pytest locally and again in CI on every push.

# in your terminal
pytest -q

Test Edge Cases on Purpose

Feed an empty frame, one row, or all-null input. Good edge case tests prove your pipeline fails loudly, not silently.

Quick Check

Which check best protects against a column being read as the wrong type?

Recap: Tests Catch Data Bugs

You now unit test data with pytest: assert shape, types, ranges, and nulls on tiny fixtures so bad data fails the build, not your users. ✅

الأسئلة الشائعة

هل درس «اختبار مسار البيانات اختباراً وحدياً» مجاني؟

نعم — نص درس «اختبار مسار البيانات اختباراً وحدياً» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة MLOps Academy، انتقل إلى CoddyKit PRO. تتضمن دورة MLOps Academy 4 دروس في المجموع.

ماذا ستتعلم في «اختبار مسار البيانات اختباراً وحدياً»؟

تحقّق باستخدام pytest من الأشكال والأنواع والنطاقات. تتمرن على MLOps Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ MLOps Academy؟

لا تُشترط خبرة سابقة. MLOps Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.

كم من الوقت يستغرق درس «اختبار مسار البيانات اختباراً وحدياً»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس MLOps Academy هذا؟

نعم. كل درس في MLOps Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. اختبار مسار البيانات اختباراً وحدياً
  2. اختبارات سلوكية للنماذج
  3. تعيين بوابات الجودة والعتبات
  4. التحقق من البيانات باستخدام Great Expectations
← العودة إلى MLOps Academy