climate_ref.models.base
#
Base
#
Bases: DeclarativeBase
Base class for all models
Source code in packages/climate-ref/src/climate_ref/models/base.py
SanitisedJSON
#
Bases: TypeDecorator[Any]
JSON column that maps non-finite floats to null.
A missing value in a metric series is entirely ordinary, so a series that contains one must still be storable. Mapping to null keeps the series the same length, which is what a consumer plotting it needs.
Source code in packages/climate-ref/src/climate_ref/models/base.py
process_bind_param(value, dialect)
#
replace_non_finite(value)
#
Replace NaN and infinities with None, recursing into lists and dicts
JSON has no literal for either.
json.dumps writes the bare tokens NaN, Infinity and -Infinity by default,
which Python reads back but PostgreSQL rejects when it validates the value on insert.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
Value about to be serialised as JSON. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The value with every non-finite float replaced by None. |