Created
May 8, 2026 10:20
-
-
Save snfnstratcha/d7a1e958122031ae4b3131e37c4211e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # /// script | |
| # requires-python = ">=3.12" | |
| # dependencies = ["pandas", "pyarrow"] | |
| # /// | |
| """ | |
| Section 1 of the article: the feature registry. | |
| Run with: | |
| uv run scripts/feature_store/01_registry.py | |
| """ | |
| from dataclasses import dataclass | |
| from typing import Literal | |
| @dataclass(frozen=True) | |
| class Feature: | |
| name: str | |
| entity: str | |
| dtype: Literal["int", "float", "str"] | |
| source: str # path to a Parquet file or a SQL view | |
| REGISTRY: dict[str, Feature] = { | |
| "user_segment": Feature("user_segment", "user_id", "str", "data/user_segment.parquet"), | |
| "watch_count_30d": Feature("watch_count_30d", "user_id", "int", "data/watch_count_30d.parquet"), | |
| "last_genre": Feature("last_genre", "user_id", "str", "data/last_genre.parquet"), | |
| } | |
| if __name__ == "__main__": | |
| print("Registered features:") | |
| for name, f in REGISTRY.items(): | |
| print(f" {name:>16} entity={f.entity} dtype={f.dtype} source={f.source}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment