Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add the DraftValidation class #60

Merged
merged 11 commits into from
Feb 14, 2025
Merged

Conversation

rich-iannone
Copy link
Member

@rich-iannone rich-iannone commented Feb 14, 2025

This adds DraftValidation, a class that can generate a validation plan based on any table that Pointblank supports. Example usage:

import pointblank as pb

nycflights = pb.load_dataset("nycflights", tbl_type="duckdb")

pb.DraftValidation(data=nycflights, model="anthropic:claude-3-5-sonnet-latest")

This generates:

import pointblank as pb

# Define schema based on column names and dtypes
schema = pb.Schema(columns=[
    ("year", "int64"), ("month", "int64"), ("day", "int64"),
    ("dep_time", "int64"), ("sched_dep_time", "int64"), ("dep_delay", "int64"),
    ("arr_time", "int64"), ("sched_arr_time", "int64"), ("arr_delay", "int64"),
    ("carrier", "string"), ("flight", "int64"), ("tailnum", "string"),
    ("origin", "string"), ("dest", "string"), ("air_time", "int64"),
    ("distance", "int64"), ("hour", "int64"), ("minute", "int64")
])

# The validation plan
validation = (
    pb.Validate(
        data=your_data,
        label="Draft Validation",
        thresholds=pb.Thresholds(warn_at=0.10, stop_at=0.25, notify_at=0.35)
    )
    .col_schema_match(schema=schema)
    .row_count_match(count=336776)
    .col_count_match(count=18)
    .rows_distinct()
    .col_vals_not_null(columns=[
        "year", "month", "day", "sched_dep_time", "sched_arr_time", 
        "carrier", "flight", "origin", "dest", "distance", "hour", "minute"
    ])
    .col_vals_eq(columns="year", value=2013)
    .col_vals_between(columns="month", left=1, right=12)
    .col_vals_between(columns="day", left=1, right=31) 
    .col_vals_between(columns="dep_time", left=1, right=2400, na_pass=True)
    .col_vals_between(columns="dep_delay", left=-43, right=1301, na_pass=True)
    .col_vals_between(columns="arr_time", left=1, right=2400, na_pass=True)
    .col_vals_between(columns="air_time", left=20, right=695, na_pass=True)
    .col_vals_between(columns="hour", left=1, right=23)
    .col_vals_between(columns="minute", left=0, right=59)
    .col_vals_gt(columns="distance", value=16)
    .col_vals_in_set(columns="origin", set=["EWR", "LGA", "JFK"])
    .interrogate()
)

validation

which, when run, is fully working and produces no failing test units:

image

Currently, this is lean on support for model providers (only Anthropic and OpenAI for now).

@codecov-commenter
Copy link

codecov-commenter commented Feb 14, 2025

Codecov Report

Attention: Patch coverage is 93.93939% with 2 lines in your changes missing coverage. Please review.

Project coverage is 99.16%. Comparing base (39cc8b2) to head (377390b).

Files with missing lines Patch % Lines
pointblank/draft.py 92.59% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #60      +/-   ##
==========================================
- Coverage   99.22%   99.16%   -0.06%     
==========================================
  Files          13       14       +1     
  Lines        2974     3003      +29     
==========================================
+ Hits         2951     2978      +27     
- Misses         23       25       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rich-iannone rich-iannone marked this pull request as ready for review February 14, 2025 17:23
@rich-iannone rich-iannone merged commit 71319d0 into main Feb 14, 2025
4 checks passed
@rich-iannone rich-iannone deleted the feat-draft-validation branch February 14, 2025 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants