Skip to content

feat: Allow to inline collection member columns for sampling#5

Merged
Oliver Borchert (borchero) merged 5 commits into
mainfrom
inline
Apr 22, 2025
Merged

feat: Allow to inline collection member columns for sampling#5
Oliver Borchert (borchero) merged 5 commits into
mainfrom
inline

Conversation

@borchero
Copy link
Copy Markdown
Member

Motivation

When providing overrides for column values in Collection.sample, it would be nice to optionally inline columns of members. What do I mean by that? Imagine that you have two members

class A(dy.Schema):
    x = dy.Int16(primary_key=True)
    y = dy.Int16()

class B(dy.Schema):
    x = dy.Int16(primary_key=True)
    z = dy.Int16()

in a collection

class C(dy.Collection):
    a: dy.LazyFrame[A]
    b: dy.LazyFrame[B]

For sampling you can currently do

C.sample(overrides=[{"a": {"y": 5}}, "b": {"z": 6}}])

However, it would be nice to "inline" the column values since it is clear what member y and z belong to, i.e. do

C.sample(overrides=[{"y": 5, "z": 6}])

This significantly reduces the amount of typing required to use overrides.

Changes

  • Introduce a new option inline_for_sampling: bool for the dy.CollectionMember annotation which can be used to inline the columns of a collection member
  • Add checks that inlining a collection member is valid (it does not work if either (1) the member is a 1:N relation, i.e. does not share the common primary key, or (2) it isn't clear which member an inlined column value would refer to)

Comment thread tests/collection/test_sample.py
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (2cf6a39) to head (ba12c24).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main        #5   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           36        36           
  Lines         1776      1788   +12     
=========================================
+ Hits          1776      1788   +12     

☔ View full report in Codecov by Sentry.
📢 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.

@borchero Oliver Borchert (borchero) enabled auto-merge (squash) April 22, 2025 10:10
@borchero Oliver Borchert (borchero) merged commit 54cbc75 into main Apr 22, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants