Skip to content

Commit

Permalink
All unit tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
wpfl-dbt committed Dec 8, 2024
1 parent f6a3225 commit 6a936d7
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/matchbox/common/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from matchbox.common.hash import HASH_FUNC
from pandas import DataFrame
from pyarrow import Table as ArrowTable
from pydantic import BaseModel, ConfigDict, Field
from pydantic import BaseModel, ConfigDict, Field, model_validator
from sqlalchemy import (
LABEL_STYLE_TABLENAME_PLUS_COL,
ColumnElement,
Expand Down Expand Up @@ -36,12 +36,24 @@
class Match(BaseModel):
"""A match between primary keys in the Matchbox database."""

cluster: bytes
cluster: bytes | None
source: str
source_id: set[str] = Field(default_factory=set)
target: str
target_id: set[str] = Field(default_factory=set)

@model_validator(mode="after")
def found_or_none(self) -> "Match":
if self.cluster is None and (self.source_id or self.target_id):
raise ValueError(
"A match must have a cluster if source_id or target_id is set."
)
elif self.cluster is not None and not (self.source_id or self.target_id):
raise ValueError(
"A match must have source_id or target_id if cluster is set."
)
return self


class Probability(BaseModel):
"""A probability of a match in the Matchbox database.
Expand Down

0 comments on commit 6a936d7

Please sign in to comment.