Add foreign key validation in Collection
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 45/100
Research direction
Start with the Schema and Collection entry points, then inspect the existing require_relationship_one_to_at_least_one and @dy.filter behavior described in the issue. Compare the requested declaration with sqlmodel's foreign_key approach. Done means collection members can declare references and missing referenced keys raise an assertion instead of being silently filtered; no file or test is named.
Written by the indexing model from the issue text.
Description
Lets say you have this basic example:
class Country(dy.Schema):
country_code = dy.String(primary_key=True)
capital = dy.String()
class CountryPair(dy.Schema):
a_country_code = dy.String(primary_key=True)
b_country_code = dy.String(primary_key=True)
distance = dy.Float64()
class MyCollection(dy.Collection):
"""Collection of all input tables for DMU balancing optimization."""
country: dy.LazyFrame[Country]
country_pair: dy.LazyFrame[CountryPair]
You might want to check/assert that a_country_code and b_country_code are present in Country.country_code.
Today you can use require_relationship_one_to_at_least_one but this will not raise a Expection but only filter.
And I would like to have something that is closer to my Collection definition. I tried to add in my Collection:
@dy.filter()
def at_least_one_diagnosis_per_invoice(self) -> pl.LazyFrame:
return self.country.select(pl.col.country_code.name.prefix("a_")).join(
self.country_pair,
on="a_country_code",
how="inner",
)
# But it fails with: ImplementationError: Members of a collection must have an overlapping primary key but did not find any
But even if this worked, I am more interesting into an assertion rather than a filter.
Do you think we can add support for foreign_key in the same manner this is done by sqlmodel
Exmaple:
class Country(dy.Schema):
country_code = dy.String(primary_key=True)
capital = dy.String()
class CountryPair(dy.Schema):
a_country_code = dy.String(primary_key=True, foreign_key="country.country_code") # reference Collection attribute
b_country_code = dy.String(primary_key=True, foreign_key="country.country_code") # reference Collection attribute
distance = dy.Float64()
class MyCollection(dy.Collection):
"""Collection of all input tables for DMU balancing optimization."""
country: dy.LazyFrame[Country]
country_pair: dy.LazyFrame[CountryPair]
- Dominant language
- Python
- Stars
- 618
- Forks
- 21
- Avg merge
- 15h 53m
- Merged PRs (30d)
- 8
Getting set up
We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Quantco/dataframely
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Quantco/dataframely#402 · 3 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 62/100
Quantco/dataframely#357 · 1 reaction ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
Quantco/dataframely#309 · 4 comments · 2 reactions ·
-
Difficulty 5/5 Over a week Newbie friendliness 45/100
Quantco/dataframely#273 · 5 comments · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
Quantco/dataframely#272 · 10 comments · 1 reaction ·
All issues in Quantco/dataframely
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
spec-kitty/spec-kitty#5319 ·
Maintainers usually reply within 1 day
-
backend::vllm diffusion multimodal
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
openai/openai-agents-python#5229 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day