Skip to content

Commit d77fb56

Browse files
committed
docs(thresholds): scope the numpy, runtime, class match_threshold and list-warning claims
- CHANGELOG: a numpy float16 or float32 threshold compares as a Python float, so a score within its rounding below it moves from TP to FD; the runtime match_threshold keeps its own check, now on every call; a class match_threshold of 85 made every list pair an FD (an identical pair did not score 0.0); every list refusal is headed `Unused threshold`. - thresholds-and-metrics: the list-of-models comparator warning is not emitted on the Python path under `from __future__ import annotations`; an Annotated field whose type is defined further down is checked too, and say which message gives which fix.
1 parent 60cc3a2 commit d77fb56

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ Each release links to full notes on the
4545
comparator threshold the field adopts, such as
4646
`LevenshteinComparator(threshold=85)`; and the `match_threshold` class
4747
attribute, also as `ModelFactory.create_model_from_fields(match_threshold=...)`.
48-
None was checked, so at 85 an identical pair scored 0.0 FD.
48+
None was checked: a field threshold of 85 scored an identical pair 0.0
49+
FD, and a class `match_threshold` of 85 made every list pair of that
50+
class an FD.
4951
- Stickler config: `"threshold"`, an adopted `"comparator_config"`
5052
threshold, and `"match_threshold"` on the model or a nested-model field.
5153
- JSON Schema: `x-aws-stickler-threshold`, an adopted
@@ -57,18 +59,20 @@ Each release links to full notes on the
5759
accepted `true` as 1, also as a `match_threshold`, and a comparator-config
5860
threshold loaded whatever its value, because it was not read. A `Decimal`,
5961
`Fraction`, numpy number or 0-d numpy array from 0.0 to 1.0 now loads on
60-
every path, converted with `float()`, so a numpy float compares as before;
61-
the comparator keeps the value it was given. Python kept such a value
62+
every path, converted with `float()`; the comparator keeps the value it
63+
was given. A numpy float16 or float32 threshold is then compared as a
64+
Python float, not in its own dtype, so a score within its rounding below
65+
the threshold is an FD where it was a TP. Python kept such a value
6266
unconverted, so a `Decimal` raised `TypeError` on a pair scoring below it,
6367
and the importers refused it. The `match_threshold` passed to `evaluate()`
64-
or `eval_for()` is outside this rule and unchanged: for a plain pydantic
65-
model it keeps its own check, and for a `StructuredModel` it is not
68+
or `eval_for()` is outside this rule: for a plain pydantic model it keeps
69+
its own check, now on every call, and for a `StructuredModel` it is not
6670
checked. Every path gives one message. It quotes the value as written,
6771
names the model and the field, says why the value fails and gives the fix
6872
in full; on the Python path it ends with where the value was set. The
6973
refusal of `ComparableField(threshold=...)` on a `List[StructuredModel]`
7074
field uses the same template, says to remove it and names the element
71-
class, and a valid one is headed `Unused threshold`. The warning for a
75+
class, and is headed `Unused threshold` whatever its value. The warning for a
7276
comparator threshold there names the model and the element class, and
7377
points at the class rather than at `<frozen abc>`. On the config path
7478
it is no longer prefixed `Invalid field configuration:` or `Error

‎docs/docs/Getting-Started/thresholds-and-metrics.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ Anything else, such as `85`, `1.5`, `-1`, `"0.9"`, `true`, NaN or infinity, rais
167167
ValueError: Invalid threshold for field 'vendor' of model 'Invoice': ComparableField sets no threshold, so the field adopts its comparator's: LevenshteinComparator(threshold=85). A threshold is the minimum similarity score for a match, from 0.0 to 1.0. 85 is above 1.0, so even identical values would not match. If 85 is a percentage, write LevenshteinComparator(threshold=0.85), or ComparableField(threshold=0.85), which wins over the comparator's. (Set at invoice_models.py:6.)
168168
```
169169

170-
A comparator threshold the field does not adopt is not checked: when the field sets its own, the comparator's is not read, and on a `List[StructuredModel]` field (an array of objects in a schema) it is never used, since its items are matched up using `match_threshold`, so it warns instead. A field threshold on a list of models that breaks the rule raises, and the message says to remove it and use `match_threshold`. A comparator's constructor never checks its threshold, since a custom comparator may use `threshold` for something else, and the comparator keeps the value you passed. The runtime `match_threshold` of `evaluate()` and `eval_for()` is outside this rule; see [Runtime Match Threshold](#4-runtime-match-threshold).
170+
A comparator threshold the field does not adopt is not checked: when the field sets its own, the comparator's is not read, and on a `List[StructuredModel]` field (an array of objects in a schema) it is never used, since its items are matched up using `match_threshold`, so it warns instead (on the Python path, only without `from __future__ import annotations`). A field threshold on a list of models that breaks the rule raises, and the message says to remove it and use `match_threshold`. A comparator's constructor never checks its threshold, since a custom comparator may use `threshold` for something else, and the comparator keeps the value you passed. The runtime `match_threshold` of `evaluate()` and `eval_for()` is outside this rule; see [Runtime Match Threshold](#4-runtime-match-threshold).
171171

172-
A field whose type is defined further down the module is checked when the class is defined, before that type exists, so stickler reads the field as adopting its comparator's threshold. Only a list of models does not, so there, and on a bare name for a list of models (`items: "ItemList"`, with `ItemList = List[Item]` below), an invalid comparator threshold raises, though the field would ignore it once resolved. The message says to remove the comparator in that case.
172+
A field whose type is defined further down the module, `Annotated` fields included, is checked when the class is defined, before that type exists, so stickler reads the field as adopting its comparator's threshold. Only a list of models does not, so there, and on a bare name for a list of models (`items: "ItemList"`, with `ItemList = List[Item]` below), an invalid comparator threshold raises, though the field would ignore it once resolved. When the annotation is visibly a list (`List["Item"]`), the message says to remove the comparator if the element is a model. An invalid field threshold on such a field, or on a bare name, gets a fix for each case: a list of models, and anything else.
173173

174174
## Meeting a Threshold
175175

0 commit comments

Comments
 (0)