ftmq.statements
Cast statement values into the canonical format of their property type.
cast_types normalizes number and date values: the parsed value goes into
value, the raw string into original_value (unless already set), and the
statement id is regenerated. Statement stores apply this on write, as the SQL
backends CAST the value column. Existing dumps are migrated via the CLI:
cast_date(value)
Get the canonical ISO (prefix) form of a date value, or None if it doesn't
parse. Partial dates ("2021", "2021-06") are kept.
cast_number(value)
Get the canonical numeric form of a value, or None if it doesn't parse.
Kept as a string (no float precision loss); a unit suffix is dropped
("5 kg" -> "5").
Source code in ftmq/statements.py
cast_statement(stmt, casters=None)
Cast a statement's value into the canonical format of its property type.
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)
Get the caster per property type, keyed as Statement.prop_type.