-
Notifications
You must be signed in to change notification settings - Fork 18
feat: Add DataFrame support in dy.Collection
#335
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
Merged
Oliver Borchert (borchero)
merged 17 commits into
Quantco:main
from
gab23r:dataframe-support-collection
May 24, 2026
+300
−63
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
51ced99
feat: Add DataFrame support in Collection
98975b5
update doctrings
16f20bf
Add serialisation
2a05ffb
accpet only None in Union
a9ef78e
mypy
c40cedb
docformatter
e86a8fd
simplify parsing schema
7020601
ci: Bump the gh-actions group with 8 updates (#338)
dependabot[bot] db31495
chore: Update pixi lockfile (#339)
quant-ranger[bot] 64207a6
build: Use cargo-auditable for rust build (#334)
delsner 7adaa03
docs: Fix docs check list items (#340)
kklein 6c4f163
chore: Update copier template to v0.5.2 (#341)
quant-ranger[bot] 2bd5934
simplify/feedbackfix
4d25476
no return generic FrameType
4bf6d8b
remove _to_lazy_dict
113e095
Merge branch 'main' into dataframe-support-collection
borchero 245f0f4
Simplify tests
borchero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| # Copyright (c) QuantCo 2025-2026 | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
| """Tests for dy.DataFrame members in collections. | ||
|
|
||
| Members annotated with dy.DataFrame are collected once during _init and stored as | ||
| DataFrames, while dy.LazyFrame members remain lazy. | ||
| """ | ||
|
|
||
| import polars as pl | ||
| import pytest | ||
|
|
||
| import dataframely as dy | ||
|
|
||
| # ------------------------------------------------------------------------------------ # | ||
| # SCHEMA # | ||
| # ------------------------------------------------------------------------------------ # | ||
|
|
||
|
|
||
| class UserSchema(dy.Schema): | ||
| id = dy.Integer(primary_key=True) | ||
| name = dy.String() | ||
|
|
||
|
|
||
| class OrderSchema(dy.Schema): | ||
| id = dy.Integer(primary_key=True) | ||
| user_id = dy.Integer() | ||
| amount = dy.Float(min=0) | ||
|
|
||
|
|
||
| class EagerCollection(dy.Collection): | ||
| """Collection with only DataFrame (eager) members.""" | ||
|
|
||
| users: dy.DataFrame[UserSchema] | ||
| orders: dy.DataFrame[OrderSchema] | ||
|
|
||
|
|
||
| class MixedCollection(dy.Collection): | ||
| """Collection with mixed DataFrame and LazyFrame members.""" | ||
|
|
||
| users: dy.DataFrame[UserSchema] | ||
| orders: dy.LazyFrame[OrderSchema] | ||
|
|
||
|
|
||
| class LazyCollection(dy.Collection): | ||
| """Collection with only LazyFrame members (traditional).""" | ||
|
|
||
| users: dy.LazyFrame[UserSchema] | ||
| orders: dy.LazyFrame[OrderSchema] | ||
|
|
||
|
|
||
| class OptionalEagerCollection(dy.Collection): | ||
| """Collection with optional DataFrame member.""" | ||
|
|
||
| users: dy.DataFrame[UserSchema] | ||
| orders: dy.DataFrame[OrderSchema] | None | ||
|
|
||
|
|
||
| # ------------------------------------------------------------------------------------ # | ||
| # FIXTURES # | ||
| # ------------------------------------------------------------------------------------ # | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def valid_data() -> dict[str, pl.DataFrame]: | ||
| return { | ||
| "users": pl.DataFrame({"id": [1, 2], "name": ["Alice", "Bob"]}), | ||
| "orders": pl.DataFrame( | ||
| {"id": [1, 2], "user_id": [1, 2], "amount": [10.0, 20.0]} | ||
| ), | ||
| } | ||
|
|
||
|
|
||
| # ------------------------------------------------------------------------------------ # | ||
| # MEMBER INFO TESTS # | ||
| # ------------------------------------------------------------------------------------ # | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("collection_cls", "expected_lazy", "expected_eager"), | ||
| [ | ||
| (EagerCollection, set(), {"users", "orders"}), | ||
| (LazyCollection, {"users", "orders"}, set()), | ||
| (MixedCollection, {"orders"}, {"users"}), | ||
| (OptionalEagerCollection, set(), {"users", "orders"}), | ||
| ], | ||
| ) | ||
| def test_member_detection( | ||
| collection_cls: type[dy.Collection], | ||
| expected_lazy: set[str], | ||
| expected_eager: set[str], | ||
| ) -> None: | ||
| members = collection_cls.members() | ||
| for name in expected_lazy: | ||
| assert members[name].is_lazy | ||
| for name in expected_eager: | ||
| assert not members[name].is_lazy | ||
| assert collection_cls.lazy_members() == expected_lazy | ||
| assert collection_cls.eager_members() == expected_eager | ||
|
|
||
|
|
||
| def test_optional_eager_member_detection() -> None: | ||
| members = OptionalEagerCollection.members() | ||
| assert not members["users"].is_optional | ||
| assert members["orders"].is_optional | ||
|
|
||
|
|
||
| # ------------------------------------------------------------------------------------ # | ||
| # ACCESS PATTERN TESTS # | ||
| # ------------------------------------------------------------------------------------ # | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("collection_cls", "expected_types"), | ||
| [ | ||
| (EagerCollection, {"users": pl.DataFrame, "orders": pl.DataFrame}), | ||
| (LazyCollection, {"users": pl.LazyFrame, "orders": pl.LazyFrame}), | ||
| (MixedCollection, {"users": pl.DataFrame, "orders": pl.LazyFrame}), | ||
| ], | ||
| ) | ||
| def test_member_access_returns_correct_type( | ||
| collection_cls: type[dy.Collection], | ||
| expected_types: dict[str, type], | ||
| valid_data: dict[str, pl.DataFrame], | ||
| ) -> None: | ||
| collection = collection_cls.validate(valid_data) | ||
| for name, expected_type in expected_types.items(): | ||
| assert isinstance(getattr(collection, name), expected_type) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.