Skip to main content

core.provenance.Sourced

core.provenance.Sourced()

Scalar with mandatory Provenance. Subclasses float so notebooks and generated calculations can divide and format values without extra coercion.

.. warning:: Provenance does NOT survive arithmetic. Any operation on a Sourced (x * 2, x / y, -x, round(x) …) returns a plain float — Python numeric dunders construct float results, and nothing re-attaches .provenance/.name/.description. (copy.copy raises TypeError because __new__ requires a provenance argument.) The audit trail therefore lives only on the registry leaf value itself. Derived quantities that need their own audit trail must be wrapped explicitly with sourced(derived_value, Provenance(kind=DERIVED, ...)).

Attributes

Name Description
magnitude Quantity-compatible alias returning the underlying float value.
source Returns the reference string of the provenance source.
url Returns the URL of the provenance source, if any.
value Returns the underlying float value of the sourced scalar.

Methods

Name Description
render_markdown Renders a Markdown representation of the sourced scalar.
to Convert the sourced scalar into a dimensionless Pint quantity.

render_markdown

core.provenance.Sourced.render_markdown()

Renders a Markdown representation of the sourced scalar.

This includes the value, description, provenance kind, source reference, and URL. It is used primarily by CLI commands to inspect values.

to

core.provenance.Sourced.to(unit='dimensionless')

Convert the sourced scalar into a dimensionless Pint quantity.

Parameters

Name Type Description Default
unit str Target unit compatible with dimensionless quantities; defaults to dimensionless. Percent is supported; physical units are not. 'dimensionless'

Returns

Name Type Description
Quantity Converted value in the requested unit, without attached provenance.

Notes

The stored scalar is dimensionless. Conversion delegates to Pint and raises its dimensionality error for incompatible target units.

Conversion does not assign physical dimensions, preserve provenance, or infer units from the scalar’s name or description.

Examples

>>> p = Provenance(kind=ProvenanceKind.ILLUSTRATIVE, ref="Example", verified="2026-11-04")
>>> Sourced(0.5, p).to("percent").magnitude
50.0
Back to top