-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschemas.py
More file actions
34 lines (28 loc) · 1005 Bytes
/
schemas.py
File metadata and controls
34 lines (28 loc) · 1005 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""
schemas.py — Pydantic data contracts for the market metrics pipeline.
All data must conform to this schema before insertion into the database.
"""
from pydantic import BaseModel, field_validator
class MarketMetricSchema(BaseModel):
"""Strict schema enforced on every row prior to database insertion."""
trade_date: str
asset_class: str
metric_name: str
sort_variable: str
quantile_type: str
quantile_bucket: int
metric_value: float
log_metric_value: float
@field_validator("asset_class")
@classmethod
def asset_class_must_be_valid(cls, v: str) -> str:
allowed = {"stock", "etp"}
if v.lower() not in allowed:
raise ValueError(f"asset_class must be one of {allowed}, got '{v}'")
return v.lower()
@field_validator("quantile_bucket")
@classmethod
def bucket_must_be_positive(cls, v: int) -> int:
if v < 1:
raise ValueError(f"quantile_bucket must be >= 1, got {v}")
return v