Skip to content

refactor!: Replace eager: bool with "lazy-in-lazy-out"#372

Open
Oliver Borchert (borchero) wants to merge 1 commit into
mainfrom
lazy-in-lazy-out
Open

refactor!: Replace eager: bool with "lazy-in-lazy-out"#372
Oliver Borchert (borchero) wants to merge 1 commit into
mainfrom
lazy-in-lazy-out

Conversation

@borchero

Copy link
Copy Markdown
Member

Motivation

Currently, we have a parameter eager: bool to govern whether validation and filtering is performed eagerly or lazily. This is a little inconsistent with what one would expect when familiar with the polars API:

  • For schema validation/filtering, we can easily replace the parameter entirely with "lazy-in-lazy-out"/"eager-in-eager-out" behavior. This also makes user code more consistent as collection is not implicit in the case of a lazy input, but requires an explicit collect.
  • For collection validation/filtering, we take the same approach as for sink_parquet: by default, we collect, but this can be "disabled" by setting lazy=True (unless the collection defines at least one eager member).

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@f32b155). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff            @@
##             main      #372   +/-   ##
========================================
  Coverage        ?   100.00%           
========================================
  Files           ?        56           
  Lines           ?      3513           
  Branches        ?         0           
========================================
  Hits            ?      3513           
  Misses          ?         0           
  Partials        ?         0           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes the eager: bool toggle from schema-level validation/filtering APIs in favor of Polars-style “lazy-in-lazy-out / eager-in-eager-out” behavior, and introduces a lazy: bool switch for collection-level validation/filtering to control whether collections are returned lazily (with restrictions when eager members exist).

Changes:

  • Refactored Schema.validate / Schema.filter to determine eager vs lazy behavior from the input frame type rather than an eager flag.
  • Updated Collection.validate / Collection.filter to use lazy: bool (default False) and added validation that lazy=True cannot be used when the collection has eager members.
  • Updated tests and benchmarks to match the new API and semantics.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/schema/test_validate.py Removes eager parametrization and adjusts expectations based on input frame type.
tests/schema/test_filter.py Updates helper and tests to rely on input frame type for eager vs lazy filtering behavior.
tests/collection/test_skip_member_validation.py Migrates collection calls from eager=False to lazy=True.
tests/collection/test_filter_validate.py Renames eager parametrization to lazy and updates calls accordingly.
tests/collection/test_dataframe_members.py Adds coverage ensuring lazy=True is rejected for collections with eager members.
tests/benches/test_schema.py Adjusts benchmark to validate either eager or lazy inputs without eager=.
tests/benches/test_collection.py Updates benchmark to use lazy=True for collection filtering.
dataframely/schema.py Removes eager parameter and implements type-driven eager vs lazy semantics; adds Polars-version guard for efficient filtering.
dataframely/collection/collection.py Replaces eager with lazy, enforces eager-member restriction, and updates eager vs lazy execution paths.
Comments suppressed due to low confidence (1)

dataframely/collection/collection.py:599

  • Collection.filter's docstring claims member frames are always eagerly collected, but the new lazy parameter allows returning a fully lazy result. The parameter description should reflect the conditional behavior.
                All data frames passed here will be eagerly collected within the method,
                regardless of whether they are a :class:`~polars.DataFrame` or
                :class:`~polars.LazyFrame`.

Comment thread dataframely/schema.py
Comment on lines +561 to +563
SchemaError: If the input data frame is eager and it misses columns or
`cast=False` and any data type mismatches the definition in this
schema. Only raised upon collection if `eager=False`.
ValidationError: If `eager=True` and in any rule in the schema is
violated, i.e. the data does not pass the validation. When
`eager=False`, a :class:`~polars.exceptions.ComputeError` is raised
Only raised upon collection if the input data frame is lazy.
Comment on lines +429 to 433
ValidationError: If `lazy=False` and any of the input data frames does not
satisfy its schema definition or the filters on this collection result
in the removal of at least one row across any of the input data frames.
If `eager=False`, a :class:`~polars.exceptions.ComputeError` is raised
If `lazy=False`, a :class:`~polars.exceptions.ComputeError` is raised
upon collecting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants