Skip to content

Support Fluent API for CheckSet Definition #13

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

Closed
flitzpiepe93 opened this issue May 4, 2025 · 1 comment
Closed

Support Fluent API for CheckSet Definition #13

flitzpiepe93 opened this issue May 4, 2025 · 1 comment
Labels
enhancement New feature or request feature request

Comments

@flitzpiepe93
Copy link
Contributor

Support Fluent API for CheckSet Definition

Description

Currently, checks must be added to a CheckSet instance using multiple separate calls to add_check():

check_set = CheckSet()
check_set.add_check(NullCheckConfig(check_id="pickup-null", columns=["tpep_pickup_datetime"]))
check_set.add_check(NullCheckConfig(check_id="dropoff-null", columns=["tpep_dropoff_datetime"]))
check_set.add_check(NumericMinCheckConfig(check_id="trip-positive", columns=["trip_distance"], min_value=0.1))

This approach works well but is somewhat verbose. To improve readability and developer experience, it would be great to support a fluent API that allows chaining:

check_set = (
    CheckSet()
    .add_check(NullCheckConfig(check_id="pickup-null", columns=["tpep_pickup_datetime"]))
    .add_check(NullCheckConfig(check_id="dropoff-null", columns=["tpep_dropoff_datetime"]))
    .add_check(NumericMinCheckConfig(check_id="trip-positive", columns=["trip_distance"], min_value=0.1))
)

Proposed Change

Update the add_check() method in the CheckSet class to return self:

class CheckSet:
    def __init__(self) -> None:
        self._checks: List[BaseCheck] = []

    def add_check(self, config: BaseCheckConfig) -> "CheckSet":
        check = config.to_check()
        self._checks.append(check)
        return self

Benefits

  • Cleaner and more expressive DSL for defining data quality checks
  • Enables inline configuration of complex check sets
  • More user-friendly and Pythonic
@flitzpiepe93
Copy link
Contributor Author

This issue was resolved as part of Merge Request #24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature request
Projects
None yet
Development

No branches or pull requests

1 participant