Validator Registry¶
The registry holds the parsers and checks a schema resolves by name.
Registry¶
Registry is the public entry point. It groups four ValidatorRegistry instances,
one per validator kind.
nyctea.validators.registry.Registry
¶
Bases: BaseModel
Registry containing all validator types.
This Pydantic model manages separate registries for each validator type, providing type-safe registration methods and centralized validator management.
Attributes:
| Name | Type | Description |
|---|---|---|
column_parsers |
ValidatorRegistry[ColumnParser]
|
Registry for column parser validators. |
column_checks |
ValidatorRegistry[ColumnCheck]
|
Registry for column check validators. |
frame_parsers |
ValidatorRegistry[FrameParser]
|
Registry for frame parser validators. |
frame_checks |
ValidatorRegistry[FrameCheck]
|
Registry for frame check validators. |
Source code in src/nyctea/validators/registry.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
__repr__()
¶
Return string representation of registry.
Source code in src/nyctea/validators/registry.py
get_validator_counts()
¶
Get count of validators in each registry.
Returns:
| Type | Description |
|---|---|
dict[str, int]
|
Dictionary mapping registry name to validator count. |
Source code in src/nyctea/validators/registry.py
register_column_check(validator)
¶
Register a column check validator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
validator
|
ColumnCheck
|
Column check to register. |
required |
register_column_parser(validator)
¶
Register a column parser validator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
validator
|
ColumnParser
|
Column parser to register. |
required |
register_frame_check(validator)
¶
Register a frame check validator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
validator
|
FrameCheck
|
Frame check to register. |
required |
register_frame_parser(validator)
¶
Register a frame parser validator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
validator
|
FrameParser
|
Frame parser to register. |
required |
ValidatorRegistry¶
nyctea.validators.registry.ValidatorRegistry
¶
Bases: Generic[T]
Type-safe registry for a specific validator type.
This generic class manages a collection of validators of a single type, providing name-based lookup, tag-based discovery, and collision detection.
Class Type Parameters:
| Name | Bound or Constraints | Description | Default |
|---|---|---|---|
T
|
The validator type this registry manages (must extend Validator). |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
validator_type |
The class of validators this registry accepts. |
Source code in src/nyctea/validators/registry.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
__init__(validator_type)
¶
Initialize a validator registry for a specific type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
validator_type
|
type[T]
|
The class of validators this registry will accept. |
required |
Source code in src/nyctea/validators/registry.py
__len__()
¶
__repr__()
¶
get(name)
¶
Get a validator by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Validator name to lookup. |
required |
Returns:
| Type | Description |
|---|---|
T
|
The validator instance. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If no validator with that name is registered. |
Source code in src/nyctea/validators/registry.py
get_by_tag(tag)
¶
has(name)
¶
list_all()
¶
list_names()
¶
register(validator)
¶
Register a validator instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
validator
|
T
|
The validator to register. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If validator is not of the correct type. |
RegistrationError
|
If a validator with the same name is already registered. |
Source code in src/nyctea/validators/registry.py
Decorators¶
nyctea.validators.decorators.ValidatorDecorator
¶
Decorator factory for functional-style validator registration.
This class provides decorators that wrap functions in anonymous validator classes and register them automatically.
Example
from nyctea.validators.registry import Registry import polars as pl
registry = Registry() decorators = ValidatorDecorator(registry)
@decorators.column_parser(name="trim") def trim(column: pl.Expr) -> pl.Expr: ... return column.str.strip_chars()
@decorators.column_check(name="positive", tags=["numeric"]) def is_positive(column: pl.Expr) -> pl.Expr: ... return column > 0
Source code in src/nyctea/validators/decorators.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
__init__(registry)
¶
Initialize decorator factory with a registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
registry
|
Registry
|
Registry where validators will be registered. |
required |
column_check(name, description='', version='1.0.0', tags=None, author='')
¶
Decorator to register a function as a column check.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Unique validator name. |
required |
description
|
str
|
Human-readable description. |
''
|
version
|
str
|
Validator version. |
'1.0.0'
|
tags
|
Sequence[str] | None
|
Optional tags for discovery. |
None
|
author
|
str
|
Validator author. |
''
|
Returns:
| Type | Description |
|---|---|
Callable[[Callable[[Expr], Expr]], Callable[[Expr], Expr]]
|
Decorator function. |
Example
@decorators.column_check(name="not_empty") def check_not_empty(column: pl.Expr) -> pl.Expr: ... return column.str.len_chars() > 0
Source code in src/nyctea/validators/decorators.py
column_parser(name, description='', version='1.0.0', tags=None, author='')
¶
Decorator to register a function as a column parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Unique validator name. |
required |
description
|
str
|
Human-readable description. |
''
|
version
|
str
|
Validator version. |
'1.0.0'
|
tags
|
Sequence[str] | None
|
Optional tags for discovery. |
None
|
author
|
str
|
Validator author. |
''
|
Returns:
| Type | Description |
|---|---|
Callable[[Callable[[Expr], Expr]], Callable[[Expr], Expr]]
|
Decorator function. |
Example
@decorators.column_parser(name="uppercase") def to_upper(column: pl.Expr) -> pl.Expr: ... return column.str.to_uppercase()
Source code in src/nyctea/validators/decorators.py
frame_check(name, description='', version='1.0.0', tags=None, author='')
¶
Decorator to register a function as a frame check.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Unique validator name. |
required |
description
|
str
|
Human-readable description. |
''
|
version
|
str
|
Validator version. |
'1.0.0'
|
tags
|
Sequence[str] | None
|
Optional tags for discovery. |
None
|
author
|
str
|
Validator author. |
''
|
Returns:
| Type | Description |
|---|---|
Callable[[Callable[[LazyFrame], LazyFrame]], Callable[[LazyFrame], LazyFrame]]
|
Decorator function. |
Example
@decorators.frame_check(name="min_rows") def check_min_rows(frame: pl.LazyFrame, min_rows: int = 1) -> pl.LazyFrame: ... count = frame.select(pl.len()).collect().item() ... if count < min_rows: ... raise ValueError(f"Expected >= {min_rows} rows, got {count}") ... return frame
Source code in src/nyctea/validators/decorators.py
frame_parser(name, description='', version='1.0.0', tags=None, author='', preserve_columns=True, preserve_rows=False)
¶
Decorator to register a function as a frame parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Unique validator name. |
required |
description
|
str
|
Human-readable description. |
''
|
version
|
str
|
Validator version. |
'1.0.0'
|
tags
|
Sequence[str] | None
|
Optional tags for discovery. |
None
|
author
|
str
|
Validator author. |
''
|
preserve_columns
|
bool
|
If True, enforce column preservation. |
True
|
preserve_rows
|
bool
|
If True, enforce row preservation. |
False
|
Returns:
| Type | Description |
|---|---|
Callable[[Callable[[LazyFrame], LazyFrame]], Callable[[LazyFrame], LazyFrame]]
|
Decorator function. |
Example
@decorators.frame_parser(name="sort_by_age", preserve_rows=True) def sort_age(frame: pl.LazyFrame) -> pl.LazyFrame: ... return frame.sort("age")
Source code in src/nyctea/validators/decorators.py
Legacy: FunctionRegistry¶
nyctea.functions.registry is the pre-Registry system. It is retained for compatibility and
scheduled for removal. New code should use Registry above.
FunctionRegistry¶
nyctea.functions.registry.FunctionRegistry
¶
Bases: BaseModel
Holds all registered functions with strict validation.
Source code in src/nyctea/functions/registry.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 | |
column_check
property
¶
Decorator for registering column checks.
column_parser
property
¶
Decorator for registering column parsers.
frame_check
property
¶
Decorator for registering frame checks.
frame_parser
property
¶
Decorator for registering frame parsers.
register_column_check(func, *, name=None)
¶
Register a column check.
Source code in src/nyctea/functions/registry.py
register_column_parser(func, *, name=None)
¶
Register a column parser.
Source code in src/nyctea/functions/registry.py
register_frame_check(func, *, name=None)
¶
Register a frame check.
Source code in src/nyctea/functions/registry.py
register_frame_parser(func, *, name=None)
¶
Register a frame parser.
Source code in src/nyctea/functions/registry.py
Wrappers¶
ColumnFunctionWrapper¶
nyctea.functions.registry.ColumnFunctionWrapper
¶
Callable wrapper that enforces column purity at invocation time.
Source code in src/nyctea/functions/registry.py
__call__(column, *args, **kwargs)
¶
Invoke the wrapped function and enforce purity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
column
|
Expr
|
Source column expression. |
required |
*args
|
Any
|
Positional arguments passed to the wrapped function. |
()
|
**kwargs
|
Any
|
Keyword arguments passed to the wrapped function. |
{}
|
Returns:
| Type | Description |
|---|---|
Expr
|
pl.Expr: Resulting expression from the wrapped function. |
Raises:
| Type | Description |
|---|---|
ColumnPurityError
|
If the input or output violates purity rules. |
RegistryError
|
If the wrapped function returns an invalid type. |
Source code in src/nyctea/functions/registry.py
FrameFunctionWrapper¶
nyctea.functions.registry.FrameFunctionWrapper
¶
Callable wrapper that enforces frame output type and shape.
Source code in src/nyctea/functions/registry.py
__call__(frame, *args, **kwargs)
¶
Invoke the wrapped function and enforce shape constraints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
LazyFrame
|
Input lazy frame. |
required |
*args
|
Any
|
Positional arguments passed to the wrapped function. |
()
|
**kwargs
|
Any
|
Keyword arguments passed to the wrapped function. |
{}
|
Returns:
| Type | Description |
|---|---|
LazyFrame
|
pl.LazyFrame: Output frame from the wrapped function. |
Raises:
| Type | Description |
|---|---|
FrameShapeError
|
If type, column set, or row count are altered. |
Source code in src/nyctea/functions/registry.py
DecoratorAdapter¶
nyctea.functions.registry.DecoratorAdapter
¶
Bases: Generic[InFunc, OutFunc]
Decorator-like helper that avoids nested functions.
Source code in src/nyctea/functions/registry.py
__call__(func=None, *, name=None)
¶
Apply registration or return a configured adapter.
Source code in src/nyctea/functions/registry.py
Signature validation¶
SignatureValidator¶
nyctea.functions.registry.SignatureValidator
¶
Utility class to enforce function signatures at registration time.
Source code in src/nyctea/functions/registry.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
validate(func, *, expected_first, expected_return, kind)
staticmethod
¶
Validate callable signature and return type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., Any]
|
Function to validate. |
required |
expected_first
|
type
|
Expected annotation for the first argument. |
required |
expected_return
|
type
|
Expected return annotation. |
required |
kind
|
str
|
Human-readable function kind for error messages. |
required |
Raises:
| Type | Description |
|---|---|
RegistryError
|
If any signature constraint is violated. |
Source code in src/nyctea/functions/registry.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
Exceptions¶
RegistryError¶
nyctea.functions.registry.RegistryError
¶
Bases: ValueError
Raised when a function cannot be registered.
ColumnPurityError¶
nyctea.functions.registry.ColumnPurityError
¶
Bases: RegistryError
Raised when a column function touches disallowed columns.
FrameShapeError¶
nyctea.functions.registry.FrameShapeError
¶
Bases: RegistryError
Raised when a frame function alters shape unexpectedly.