Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
e364b7a
fix(importers): resolve unstated threshold and clip as the Python pat…
sromoam Oct 15, 2026
adbda67
fix(importers): credit a zero threshold to the comparator only when i…
sromoam Oct 16, 2026
3637981
Merge origin/dev into fix/334-348-importer-defaults
sromoam Oct 28, 2026
530e77f
test: pin the free-form clip default from #334 in the extension refer…
sromoam Oct 28, 2026
ede3216
Merge remote-tracking branch 'origin/dev' into m408
sromoam Oct 29, 2026
60703e0
fix(334): name an adopted comparator threshold in the explain() trail
sromoam Oct 29, 2026
626f6dd
fix(348): resolve comparator keys on a nested model as the Python pat…
sromoam Oct 29, 2026
7dfab62
docs(348): document the nested-model comparator warning and the new d…
sromoam Oct 29, 2026
83f1556
docs(348): say the nested-object default threshold is fixed, not the …
sromoam Oct 30, 2026
6e51532
fix(348): plural warning verbs, keep ValueError for a list comparator…
sromoam Oct 30, 2026
fe8b830
Merge origin/dev into fix/334-348-importer-defaults
sromoam Nov 17, 2026
c6878eb
fix(importers): check an adopted comparator threshold and resolve nes…
sromoam Nov 17, 2026
2934248
docs(importers): state the threshold and clip defaults the importers …
sromoam Nov 17, 2026
dad0ca9
fix(importers): load a comparator that requires threshold on an array…
sromoam Nov 17, 2026
f7a4640
test(importers): pin the union, nested-warning and explain() behaviou…
sromoam Nov 17, 2026
1caa1cb
docs(importers): correct the free-form clip, nested comparator and wa…
sromoam Nov 17, 2026
ff19b01
docs(importers): scope the free-form clip claim to each object, and n…
sromoam Nov 17, 2026
a7ab802
docs(thresholds): state that an invalid field threshold raises, on ev…
sromoam Nov 17, 2026
09dcedd
fix(thresholds): raise on a field threshold that is not a number from…
sromoam Nov 17, 2026
a17802c
test(thresholds): pin the raise for an invalid field threshold on eve…
sromoam Nov 17, 2026
4f0fb4a
docs(thresholds): one message per path, int or float only, match_thre…
sromoam Nov 17, 2026
f5ad746
fix(thresholds): check Annotated fields, quote values as written, no …
sromoam Nov 17, 2026
3991537
test(thresholds): pin the per-path messages, Annotated, postponed ann…
sromoam Nov 17, 2026
be9b0b0
fix(thresholds): load an in-range Decimal, Fraction or numpy threshol…
sromoam Nov 17, 2026
d78cb3c
fix(thresholds): give every threshold message a fix, and the list ref…
sromoam Nov 17, 2026
526061b
fix(thresholds): check a forward-referenced field when the class is d…
sromoam Nov 17, 2026
7aa8375
docs(thresholds): a number from 0.0 to 1.0, on the class, config and …
sromoam Nov 17, 2026
55e4023
fix(thresholds): keep the runtime match_threshold check of evaluate()…
sromoam Nov 17, 2026
1654b58
fix(thresholds): check forward-referenced lists, keep numpy verdicts,…
sromoam Nov 17, 2026
32febb2
fix(importers): name a titled schema's model in its warnings, and say…
sromoam Nov 17, 2026
89b7e07
docs(thresholds): scope the runtime check, forward-referenced lists, …
sromoam Nov 17, 2026
9794614
docs(thresholds): a bare alias name for a list is ignored once resolv…
sromoam Nov 17, 2026
9d4a8a5
chore: merge origin/dev into fix/334-348-importer-defaults
sromoam Nov 17, 2026
0cad533
fix(thresholds): check an Annotated field whose type is defined furth…
sromoam Nov 17, 2026
4e59553
docs(thresholds): numpy float16 and float32 compare as Python floats,…
sromoam Nov 17, 2026
f7c7782
fix(auto): a runtime match_threshold=False does not warn that the thr…
sromoam Nov 17, 2026
60cc3a2
fix(thresholds): correct the threshold messages whose advice was wron…
sromoam Nov 17, 2026
d77fb56
docs(thresholds): scope the numpy, runtime, class match_threshold and…
sromoam Nov 17, 2026
e9228d7
fix(thresholds): evaluate Annotated metadata as pydantic does, once p…
sromoam Nov 17, 2026
44d21f9
fix(thresholds): a list-of-models message no longer tells an element …
sromoam Nov 17, 2026
96f5567
fix(thresholds): an unresolved dict or tuple gets the usual fix, and …
sromoam Nov 17, 2026
c4612ba
docs(thresholds): scope the Python list warning, name match_threshold…
sromoam Nov 17, 2026
9b2b5a9
docs(changelog): rewrap the threshold-rule paragraph
sromoam Nov 17, 2026
3a18858
test(thresholds): pin that a numpy float16 or float32 match_threshold…
sromoam Nov 17, 2026
cb26400
test(thresholds): drop the postponed Annotated case from the dict-or-…
sromoam Nov 17, 2026
8ce3b28
Revert "fix(thresholds): evaluate Annotated metadata as pydantic does…
sromoam Nov 17, 2026
5d85b9b
Revert "fix(thresholds): check an Annotated field whose type is defin…
sromoam Nov 17, 2026
605ea32
docs(thresholds): an Annotated field written as a string that names s…
sromoam Nov 17, 2026
a5230d5
fix(thresholds): a class loads when the working directory no longer e…
sromoam Nov 18, 2026
d86e94e
docs(importers): a threshold a custom comparator's constructor sets i…
sromoam Nov 18, 2026
43579b1
docs(thresholds): scope the Annotated, numpy float64 and array-sentin…
sromoam Nov 18, 2026
2b8d1b0
fix(evaluate): a runtime match_threshold of any real type in range is…
sromoam Nov 18, 2026
f7149a4
docs(thresholds): scope the Set at, None and unread-key claims
sromoam Nov 18, 2026
a93086a
docs(changelog): give the TP-to-FD example for a comparator's constru…
sromoam Nov 18, 2026
726726f
ci(thresholds): mark the test's exec calls reviewed, and skip the mad…
sromoam Nov 18, 2026
f0800a4
Merge origin/dev into fix/334-348-importer-defaults
sromoam Nov 23, 2026
b78859f
test(thresholds): patch in the NaN threshold the report test needs
sromoam Nov 23, 2026
e7ccbdc
test(thresholds): name the bool match_threshold test for the refusal …
sromoam Nov 23, 2026
619b714
fix(importers): name the model in the nested-model warnings as the er…
sromoam Nov 23, 2026
006f558
Merge dev into fix/334-348-importer-defaults
sromoam Nov 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(importers): credit a zero threshold to the comparator only when i…
…t named one

Review of the previous commit. Clearing `_threshold_explicit` on importer
defaults made the zero-threshold warning read "sets comparator threshold=0.0"
for an inferred mapping threshold copied from `match_threshold: 0.0`. It now
credits the comparator only when the comparator named the threshold.

Also: tests for the list-of-mappings clip default, the schema free-form object
default, and the object-property refusal across type-list, anyOf, $ref and
allOf spellings; CHANGELOG no longer says the importer gate was always 0.5.
  • Loading branch information
sromoam committed Oct 16, 2026
commit adbda67004ae3b3954aa3b823d43a6908cc79c58
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ Each release links to full notes on the
defaults that key on that were skipped:
- **A threshold named on the comparator reaches the field.**
`"comparator_config": {"threshold": 0.9}` (or
`x-aws-stickler-comparator-config`) with no field `threshold` gated at 0.5,
so a pair scoring 0.78 was a TP there and an FD in Python. It is 0.9 on all
`x-aws-stickler-comparator-config`) with no field `threshold` gated at the
importer's own default instead (0.5 for a string), so a pair scoring 0.78
was a TP there and an FD in Python. It is 0.9 on all
three paths now. A field threshold still wins, and a comparator threshold
outranks an inferred one
([#334](https://github.com/awslabs/stickler/issues/334)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -717,13 +717,25 @@ def __init_subclass__(cls, **kwargs):
# "sets threshold=0.0" points at a `ComparableField` argument
# absent from the call site -- the same misattribution this
# PR fixes for the `List[StructuredModel]` error one screen up.
field_wrote_it = getattr(
field_default.json_schema_extra, "_threshold_explicit", True
#
# "Not stated on the field" does not imply "from the
# comparator": an importer clears the marker on its own
# defaults too, and an inferred mapping threshold copies a
# `match_threshold` of 0.0. So the comparator is credited only
# when it actually named a threshold.
extra = field_default.json_schema_extra
from_comparator = not getattr(
extra, "_threshold_explicit", True
) and (
_named_comparator_threshold(
getattr(extra, "_comparator_instance", None)
)
is not None
)
_warn_if_threshold_is_zero(
temp_schema["x-comparison"].get("threshold"),
f"{_model_identity(cls.__name__, cls.__annotations__)}.{field_name}",
"threshold" if field_wrote_it else "comparator threshold",
"comparator threshold" if from_comparator else "threshold",
)

# `match_threshold` is a plain class attribute rather than a field, so
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
``test_object_property_threshold.TestTheComparatorOnTheSameNodeIsRefused``.
"""

from typing import Any, Dict, Optional
import warnings
from typing import Any, Dict, List, Optional

import pytest

Expand All @@ -32,6 +33,7 @@
from stickler.structured_object_evaluator.models.structured_model import (
StructuredModel,
)
from stickler.utils import deprecation

# Levenshtein scores this pair 0.7778: a TP at the legacy 0.5, an FD at 0.9.
GT_CODE, PRED_CODE = "ACME-1000", "ACNE-1009"
Expand Down Expand Up @@ -265,3 +267,87 @@ def test_a_scalar_field_still_clips_by_default(self):
sch = _schema({"type": "string"})
assert _info(cfg).clip_under_threshold is True
assert _info(sch).clip_under_threshold is True


class TestAListOfMappingsKeepsItsPartialCreditOnEveryPath:
"""The list form of the mapping case, which the CHANGELOG entry also names."""

def test_the_three_paths_agree(self):
paths = {
"python": _python(
List[Dict[str, Any]],
ComparableField(comparator=ANLSStarComparator()),
),
"config": _config(
{"type": "List[Dict[str, Any]]", "comparator": "ANLSStarComparator"}
),
"schema": _schema(
{
"type": "array",
"items": {"type": "object", "additionalProperties": True},
"x-aws-stickler-comparator": "ANLSStarComparator",
}
),
}
assert {_info(m).clip_under_threshold for m in paths.values()} == {False}
scores = {
name: _verdict(m, [GT_META], [PRED_META])[0] for name, m in paths.items()
}
assert scores["config"] == scores["schema"] == scores["python"]
assert scores["python"] == pytest.approx(1 / 3)


class TestTheSchemaFreeFormObjectDefault:
"""Exact at 1.0 is unchanged (#348 item 1); only its clip reads false."""

def test_clip_is_off_and_the_comparator_is_unchanged(self):
info = _info(_schema({"type": "object", "additionalProperties": True}))
assert type(info.comparator).__name__ == "ExactComparator"
assert info.threshold == 1.0
assert info.clip_under_threshold is False


class TestAZeroThresholdWarningNamesItsSource:
"""Clearing the marker on an importer default must not credit the comparator.

"Not stated on the field" used to imply "adopted from the comparator", so
an inferred mapping threshold copied from `match_threshold: 0.0` was
reported as "sets comparator threshold=0.0", naming a key nobody wrote.
"""

@pytest.fixture(autouse=True)
def _fresh_warn_once(self):
deprecation._warned.clear()
yield
deprecation._warned.clear()

def _messages(self, build):
with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter("always")
build()
return [str(w.message) for w in caught if "=0.0" in str(w.message)]

def test_an_inferred_zero_is_not_attributed_to_the_comparator(self):
messages = self._messages(
lambda: StructuredModel.model_from_json(
{
"model_name": "ZeroInferred",
"match_threshold": 0.0,
"infer_unspecified_fields": True,
"fields": {"meta": {"type": "Dict[str, Any]"}},
}
)
)
assert any("ZeroInferred.meta sets threshold=0.0" in m for m in messages)
assert not any("comparator threshold" in m for m in messages)

def test_a_comparator_zero_still_is(self):
messages = self._messages(
lambda: _schema(
{
"type": "string",
"x-aws-stickler-comparator-config": {"threshold": 0.0},
}
)
)
assert any(".f sets comparator threshold=0.0" in m for m in messages)
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ def test_the_sentinel_is_still_silent_across_repeats(self):


class TestAnArrayOfFreeFormObjectsReadsIt:
""""Array of MODELS" ignores it; "array of objects" is not the same thing.
""" "Array of MODELS" ignores it; "array of objects" is not the same thing.

The distinction is `items` declaring `properties`. Without them the array
becomes `List[dict]`, which READS the declared threshold and warns about
Expand Down Expand Up @@ -507,6 +507,44 @@ def test_a_declared_comparator_is_refused_on_an_object_property(self, key, value
with pytest.raises(ValueError, match=f"{key} is not read on field 'inner'"):
StructuredModel.from_json_schema(_schema(**{key: value}))

@pytest.mark.parametrize(
"prop",
[
pytest.param(dict(CHILD, type=["object", "null"]), id="type-list-null"),
pytest.param({"anyOf": [CHILD, {"type": "null"}]}, id="anyOf-null"),
pytest.param({"$ref": "#/$defs/Child"}, id="ref"),
pytest.param({"allOf": [{"$ref": "#/$defs/Child"}]}, id="allOf-ref"),
],
)
def test_every_spelling_of_an_object_property_refuses_it(self, prop):
schema = {
"type": "object",
"title": "Parent",
"$defs": {"Child": CHILD},
"properties": {
"inner": dict(prop, **{"x-aws-stickler-comparator": "ExactComparator"})
},
}
with pytest.raises(ValueError, match="is not read on field 'inner'"):
StructuredModel.from_json_schema(schema)

def test_a_free_form_object_still_honours_it(self):
"""No `properties`, so it is one value scored by its comparator."""
model = StructuredModel.from_json_schema(
{
"type": "object",
"title": "Parent",
"properties": {
"inner": {
"type": "object",
"x-aws-stickler-comparator": "ANLSStarComparator",
}
},
}
)
resolved = model._get_comparison_info("inner").comparator
assert type(resolved).__name__ == "ANLSStarComparator"

def test_a_scalar_property_honours_the_same_key(self):
"""The contrast, so this reads as an asymmetry rather than a global."""
model = StructuredModel.from_json_schema(
Expand Down
Loading