Statements
Cast statement values into the canonical format of their property type.
cast_types normalizes number and date values in a statement stream: the
parsed value goes into value, the raw string into original_value (unless
that already carries a source value), and the statement id (a content hash
over value) is regenerated for every changed statement. Statement store
writers apply this on write; existing dumps are migrated via the CLI:
The SQL backends CAST the value column when aggregating or sorting
numerically, so stored values must be in this format.
cast_date(value)
The canonical ISO(-prefix) form of a date value, or None if it doesn't
parse. Partial dates ("2021", "2021-06") are kept as they are.
cast_number(value)
The canonical numeric form of a value, or None if it doesn't parse.
This is the string registry.number.to_number reads (same parser, same
rejections), kept as a string instead of a float: the float round trip
would lose precision beyond 15 digits. A unit suffix is dropped
("5 kg" -> "5") and survives in original_value.
Source code in ftmq/statements.py
cast_statement(stmt, casters=None)
Cast one statement's value into the canonical format of its property
type, or None if the value doesn't parse (it is logged as it goes by).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stmt
|
Statement
|
The statement to cast |
required |
casters
|
dict[str, Caster] | None
|
Caster per property type (default: |
None
|
Returns:
| Type | Description |
|---|---|
Statement | None
|
The statement, cloned if its value changed, or |
Source code in ftmq/statements.py
cast_types(statements, types=DEFAULT_TYPES, drop_invalid=False)
Normalize the values of the given property types in a statement stream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
statements
|
Iterable[Statement]
|
Stream of statements |
required |
types
|
Iterable[str]
|
Property types to cast (default: |
DEFAULT_TYPES
|
drop_invalid
|
bool
|
Drop statements whose value doesn't parse instead of passing them through unchanged |
False
|
Returns:
| Type | Description |
|---|---|
Iterator[Statement]
|
A generator of |
Source code in ftmq/statements.py
get_casters(types)
The caster per property type, keyed as Statement.prop_type.