dpmxl.values¶
Values and their comparison. See Interval arithmetic.
dpmxl.values
¶
Runtime values: numbers with interval thresholds, items, text, dates.
Numbers follow the Eurofiling interval arithmetic functions (iaf:*) that
EBA validation rules are based on: a number is a value with a symmetric
threshold, so it stands for the interval [value - t, value + t]. Facts
reported with XBRL decimals get t = 0.5 * 10**-decimals (INF is
exact); constants and defaults are exact. Sums and differences add
thresholds, products use |A*dB| + |B*dA| + dA*dB, quotients take the
largest deviation of the endpoint quotients, abs and negation keep the
threshold, and min/max keep the chosen value's threshold. Two numbers
are equal when |a - b| <= ta + tb, i.e. when their intervals overlap.
Selections evaluated with interval: false drop the threshold, so their
comparisons are exact.
Arithmetic uses DECIMAL_CONTEXT (34 significant
digits, as IEEE decimal128), whatever the caller's thread decimal context.
DECIMAL_CONTEXT
module-attribute
¶
DECIMAL_CONTEXT = Context(
prec=34,
rounding=ROUND_HALF_EVEN,
Emax=6144,
Emin=-6143,
traps=[DivisionByZero, InvalidOperation, Overflow],
)
The decimal context of every operation on numbers (IEEE decimal128).
Value
module-attribute
¶
Number
dataclass
¶
A decimal value with a symmetric tolerance for interval arithmetic.
A number stands for the interval
[value - tolerance, value + tolerance]. Build reported facts with
Number.of, which derives the tolerance from
XBRL decimals. Arithmetic operators
(+, -, *, /, unary - and abs) follow the interval
rules in the module documentation.
Attributes:
-
value(Decimal) –The amount.
-
tolerance(Decimal) –Half-width of the interval; 0 for an exact number.
Examples:
low
property
¶
of
classmethod
¶
of(
value: int | str | Decimal,
decimals: int | str | None = None,
) -> Number
Build a number, deriving tolerance from XBRL decimals.
Parameters:
-
value(int | str | Decimal) –The amount.
-
decimals(int | str | None, default:None) –XBRL
decimals: an integer,"INF"(in any case) orNone, which both mean exact.
Returns:
Raises:
-
ValueError–If
decimalsis text other thanINFor an integer, or puts the tolerance outside the range ofDECIMAL_CONTEXT(beyond about ±6,100).
Examples:
__add__
¶
__sub__
¶
__mul__
¶
Multiply as Eurofiling's iaf:numeric-multiply does.
The threshold is |A * dB| + |B * dA| + dA * dB.
Returns:
-
Number(Number) –The result.
__truediv__
¶
Divide as Eurofiling's iaf:numeric-divide does.
The threshold is the largest deviation of the four endpoint quotients
(A ± dA) / (B ± dB) from A / B. An endpoint divisor of zero is
skipped rather than making the result unbounded.
Returns:
-
Number(Number) –The quotient.
Raises:
-
ZeroDivisionError–If
otheris zero.
ValueSet
dataclass
¶
ValueSet(members: tuple[Value, ...] = ())
A set of distinct scalar values.
Set literals, set-* parameters and set operators yield sets. Members are kept in
first-seen order; numbers are exact, so 1 and 1.0 are one member. Build sets
with ValueSet.of, which removes duplicates by DPM-XL
equality.
members
class-attribute
instance-attribute
¶
members: tuple[Value, ...] = ()
The members in first-seen order.
of
classmethod
¶
Collect distinct non-null values.
Returns:
-
ValueSet(ValueSet) –The set, in first-seen order.
Raises:
-
TypeError–If a value is itself a set.
Examples:
__contains__
¶
Whether a member equals value (numbers by interval overlap).
Returns:
-
bool(bool) –Membership.
compare
¶
Compare two scalar values with DPM-XL semantics.
Numbers use interval comparison: a = b holds when the tolerance
intervals overlap. Items compare by category and code, ignoring a missing
category. Null on either side yields null.
Returns:
-
bool | None–bool | None: The comparison result, or
Nonefor null operands.
Raises:
-
TypeError–When the operands cannot be compared.
-
ValueError–When
opis not a comparison operator.
Examples:
format_value
¶
format_value(value: Value) -> str
Format a value for an explanation.
Numbers use thousands separators and drop trailing zeros; items keep their
category:code form in brackets.
Returns:
-
str(str) –Human-readable text.
Examples:
format_decimal
¶
format_computed
¶
Format a computed decimal, rounding a long fraction for display.
A division yields up to 34 significant digits. Beyond ten decimals, the
number shows six significant digits, but keeps every integer digit and
two decimals:
1.852935352358765... reads 1.85294 and 12345.67890123456
12,345.68. Shorter fractions, such as the exact difference of two
reported values, are shown in full, as reported values always are.
Returns:
-
str(str) –The formatted number.
Examples: