Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Add foreign key validation in Collection

Đang mở
#295 3 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
45/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
python
Lĩnh vực
data

Hướng nghiên cứu

Bắt đầu với các entry point của Schema và Collection, sau đó kiểm tra hành vi hiện có của require_relationship_one_to_at_least_one và @dy.filter được mô tả trong issue. So sánh khai báo được yêu cầu với cách tiếp cận foreign_key của sqlmodel. Hoàn thành nghĩa là các member của collection có thể khai báo các reference và các key được reference nhưng bị thiếu sẽ tạo ra một assertion thay vì bị lọc một cách âm thầm; không có file hoặc test nào được nêu tên.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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]

Ngôn ngữ chính
Python
Star
618
Fork
21
Merge trung bình
14 giờ 34 phút
Pull request đã merge (30 ngày)
7

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Quantco/dataframely

Tất cả issue của Quantco/dataframely

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.