Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
b74079d
fix(400): classify a list item's primitive sub-field through the disp…
sromoam Oct 15, 2026
e7810fa
fix(400): widen the CHANGELOG and tests to every path the guard covers
sromoam Oct 15, 2026
89fd840
Merge remote-tracking branch 'origin/dev' into fix/400-any-dict-in-li…
sromoam Oct 16, 2026
3145138
Merge origin/dev into fix/400-any-dict-in-list-item
sromoam Oct 28, 2026
e2377a5
Merge origin/dev into fix/400-any-dict-in-list-item
sromoam Nov 17, 2026
2c43b0e
fix(400): read list sub-fields as top level does, and keep empty list…
sromoam Nov 17, 2026
992fc09
test(400): pin list sub-field counts instead of comparing two dispatc…
sromoam Nov 17, 2026
e30e6be
refactor(400): delete the list sub-field classifier, which has no caller
sromoam Nov 17, 2026
2452289
test(400): reword a comment the docs-drift guard flags
sromoam Nov 17, 2026
8252c77
docs(400): list every count the list path moves, and narrow the parit…
sromoam Nov 17, 2026
ad608ac
fix(400): count a model of another class in a list sub-field as dev does
sromoam Nov 17, 2026
0999f7a
fix(400): count every pair under aggregate when a sub-field mixes shapes
sromoam Nov 17, 2026
a9a9542
test(400): pin a non-recursing compare_with override, update a docstring
sromoam Nov 17, 2026
b26a6b5
docs(400): describe the other-class and mixed-shape counts, fix the e…
sromoam Nov 17, 2026
95f16be
fix(400): leave a list-annotated sub-field's other-class pairs to the…
sromoam Nov 17, 2026
0a52737
fix(400): read only a non-list sub-field's empty values by value
sromoam Nov 17, 2026
01b2c9f
docs(400): scope the list sub-field rules to non-nested, non-list fields
sromoam Nov 17, 2026
9a4b615
test(400): pin a list against None in an Any sub-field at one FN
sromoam Nov 17, 2026
b643ce2
docs(400): widen the AttributeError paragraph, and name the TP it now…
sromoam Nov 17, 2026
1f0973d
docs(400): file the list sub-field entry under Fixed, not Breaking
sromoam Nov 17, 2026
f755ea4
docs(400): say a subclass for its base is a TP in an Any sub-field
sromoam Nov 17, 2026
f98703e
test(400): pin the base-first list, the other-class pair TP and the w…
sromoam Nov 17, 2026
2df3183
refactor(400): drop a model check no matched pair can fail
sromoam Nov 17, 2026
f17b715
test(400): pin an other-class pair at the default threshold as a TP
sromoam Nov 17, 2026
b756a79
docs(400): say an other-class pair whose unset field matches is a TP
sromoam Nov 17, 2026
e069405
docs(400): name the list pairing TP in the different-classes warning
sromoam Nov 17, 2026
f9f0fc3
docs(400): name the fixed-score override row and the ground-truth crash
sromoam Nov 17, 2026
e40c334
fix(400): keep a self-scoring non-model GT item out of field classifi…
sromoam Nov 17, 2026
e414a7c
docs(400): name the List[Any] and other-class crash shapes, and the o…
sromoam Nov 17, 2026
bfea4ad
docs(400): say a whitespace string or empty tuple against [] is no lo…
sromoam Nov 17, 2026
9ae4385
docs(400): call the fixed-score override row's TP unsettled, not fixed
sromoam Nov 17, 2026
1269607
docs(400): say the ground-truth raise needs a model first and a match…
sromoam Nov 17, 2026
776449e
docs(400): list every null value an empty tuple or whitespace string …
sromoam Nov 17, 2026
eee3e1b
Merge remote-tracking branch 'origin/dev' into fix/400-any-dict-in-li…
sromoam Nov 17, 2026
e34e9b8
docs(400): name every fixed-score override row as a TP, as without th…
sromoam Nov 17, 2026
5dc6c0e
test(400): pin every fixed-score override row at a TP
sromoam Nov 17, 2026
0100113
docs(400): except a union field two classes declare differently from …
sromoam Nov 17, 2026
3446fe5
test(400): pin a union field two classes declare differently, in both…
sromoam Nov 17, 2026
ce4a97d
docs(400): rewrap an over-long CHANGELOG line
sromoam Nov 17, 2026
f39c15f
docs(400): name the fixed crash for a self-scoring non-model ground-t…
sromoam Nov 17, 2026
eeb73f9
test(400): pin a Sequence sub-field at per-element counts, as at top …
sromoam Nov 17, 2026
9f85e15
test(400): pin an Optional[Annotated[Inner, Field(...)]] sub-field as…
sromoam Nov 17, 2026
e2d3287
docs(400): state the list sub-field rule in the CHANGELOG, with examples
sromoam Nov 17, 2026
5814586
docs(400): say which list sub-fields are read by value, by example
sromoam Nov 17, 2026
15ffdc2
fix(400): count a list an override element cannot score as dev did
sromoam Nov 17, 2026
57d5c1c
test(400): pin an override element's unscorable list at dev's FD
sromoam Nov 17, 2026
cd3fb59
docs(400): say an override element's unscorable list counts as before
sromoam Nov 17, 2026
f32912a
docs(400): except plain pydantic elements from the non-model pair TP
sromoam Nov 17, 2026
b0890cc
docs(400): note the comparator fallback in the refactoring record
sromoam Nov 17, 2026
fac2680
test(400): pin a dispatched sub-field of mixed shapes leaving the oth…
sromoam Nov 18, 2026
780c213
test(400): pin an extra field on a predicted list element as uncounted
sromoam Nov 18, 2026
f1aa451
test(400): pin a fixed-score element's sub-field warning as without it
sromoam Nov 18, 2026
7b8841c
docs(400): scope the CHANGELOG's mixed-shapes case to every sub-field
sromoam Nov 18, 2026
5654027
docs(400): say the CHANGELOG's uncounted field is an extra one on the…
sromoam Nov 18, 2026
a5e8aa0
docs(400): say a fixed-score element's sub-fields now warn as without it
sromoam Nov 18, 2026
9ab8ec9
docs(400): say which pairs of model classes warn under a fixed-score …
sromoam Nov 18, 2026
dfc5cc1
test(400): check the fixed-score warning and its raise in separate tests
sromoam Nov 18, 2026
ff33e1b
fix(400): count a fixed-score model a fixed-score element cannot scor…
sromoam Nov 18, 2026
5746007
test(400): pin a fixed-score model under a fixed-score element at dev…
sromoam Nov 18, 2026
823c451
docs(400): say a fixed-score element's model pair the dispatcher rais…
sromoam Nov 18, 2026
b9ab522
fix(400): count a list sub-field the first element's class does not r…
sromoam Nov 18, 2026
c8e5d72
test(400): pin a list sub-field the first element's class does not ro…
sromoam Nov 18, 2026
efa47ca
docs(400): say a list sub-field the first element's class does not ro…
sromoam Nov 18, 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(400): leave a list-annotated sub-field's other-class pairs to the…
… dispatcher

ad608ac classified two models of different classes by `compare_with()` in
every non-nested sub-field. Dev did that only for a field that is not
list-annotated. A list-annotated one, such as `Union[Search, Browse,
List[str]]` or `Union[Any, List[str]]`, took the simple-list branch, which
sent every pair to the dispatcher. So `Search(query="hotels")` vs
`Browse(url="x.com")` there moved from TP with `aggregate` fn1 to FD, and
`Inner(a, b)` vs `Other(c)` lost its fn2 leaves.

Read the annotation first and use `compare_with()` only when the field is
not list-annotated. A test pins both rows and the `Optional[Union[...]]`
case, which is routed as a nested model, at the counts top level gives.
  • Loading branch information
sromoam committed Nov 17, 2026
commit 95f16be51f3d4f19518c18f023872456805ab2bb
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,9 @@ def _dispatch_pairs(
Args:
other_class_by_compare_with: Classify two models of different
classes by :func:`_other_class_result` instead of the
dispatcher. Set for a sub-field not routed as a nested model,
such as ``Any`` or ``Union[A, B]``.
dispatcher. Set for a sub-field that is neither routed as a
nested model nor list-annotated, such as ``Any`` or
``Union[A, B]``.
"""
pair_results = []
for gt_idx, pred_idx, _ in matched_pairs:
Expand Down Expand Up @@ -577,29 +578,33 @@ def _handle_non_hierarchical_field(
Handles both true primitive fields (str, int, etc.) and simple list fields
(List[str], List[int], etc.). Every pair is classified through
_dispatch_field_comparison, as at top level, so a simple list field uses
PrimitiveListComparator for element-level comparison. A model held in an
``Any`` or ``Union`` field keeps its nested ``fields`` for ``aggregate``
when every pair has them. A model of another class than the GT value is
classified by its ``compare_with()`` score and has no nested ``fields``.
PrimitiveListComparator for element-level comparison, and keeps its
nested ``fields``. In any other field, such as ``Any`` or
``Union[A, B]``, a model keeps its nested ``fields`` for ``aggregate``
when every pair has them, and a model of another class than the GT
value is classified by its ``compare_with()`` score, with no nested
``fields``.

Args:
owner: The model class that declares ``sub_field_name``.

See: https://github.com/awslabs/stickler/issues/33
"""
is_simple_list = _annotation_is_list(owner.model_fields[sub_field_name].annotation)
# Classify through the dispatcher, as top level does. Calling the
# comparator directly skipped its guards, so a dict it cannot score
# raised instead of scoring an FD (#400).
# raised instead of scoring an FD (#400). A list-annotated field, such
# as `Union[A, B, List[str]]`, sent every pair to the dispatcher before
# too, including two models of different classes.
pair_results = self._dispatch_pairs(
sub_field_name,
gt_list,
pred_list,
matched_pairs,
other_class_by_compare_with=True,
other_class_by_compare_with=not is_simple_list,
)
aggregated_result = self._recursive_aggregate_metrics(pair_results)

is_simple_list = _annotation_is_list(owner.model_fields[sub_field_name].annotation)
# `aggregate` sums a node's children when it has any, so keep the
# subtree only if every pair has one. Otherwise a pair with flat
# counts, such as a model against `None`, would drop out of it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
The list path now goes through the dispatcher. Three rules hold on top of it:
an empty list is null by its value, as `classification-logic.md` says; a pair
is read on its GT item's own fields, so a list of mixed model classes does not
raise; and two models of different classes in an `Any` or `Union` sub-field
are classified by `compare_with()`, as before. A sub-field keeps its nested
`fields` only when every pair has them, so every pair counts under
raise; and two models of different classes in a sub-field that is neither
routed as a nested model nor list-annotated, such as `Any` or `Union[A, B]`,
are classified by `compare_with()`, as before. Such a sub-field keeps its
nested `fields` only when every pair has them, so every pair counts under
`aggregate`. Every expected count below is a literal, so a change to the
dispatcher shows up here. See https://github.com/awslabs/stickler/issues/400
"""
Expand Down Expand Up @@ -281,6 +282,85 @@ def test_a_model_of_another_class_in_a_sub_field_is_scored_by_compare_with(
assert not node.get("fields")


class OptionalUnionElement(StructuredModel):
key: str = ComparableField(threshold=1.0)
value: Optional[Union[Search, Browse]] = ComparableField(threshold=0.9)
match_threshold = 0.4


class OptionalUnionHolder(StructuredModel):
items: List[OptionalUnionElement] = ComparableField()


class ListArmUnionElement(StructuredModel):
key: str = ComparableField(threshold=1.0)
value: Union[Search, Browse, List[str]] = ComparableField(threshold=0.9)
match_threshold = 0.4


class ListArmUnionHolder(StructuredModel):
items: List[ListArmUnionElement] = ComparableField()


class ListArmAnyElement(StructuredModel):
key: str = ComparableField(threshold=1.0)
value: Union[Any, List[str]] = ComparableField(threshold=0.9)
match_threshold = 0.4


class ListArmAnyHolder(StructuredModel):
items: List[ListArmAnyElement] = ComparableField()


@pytest.mark.parametrize(
"holder, element, gt, pred, aggregate",
[
pytest.param(
OptionalUnionHolder,
OptionalUnionElement,
Search(query="hotels"),
Browse(url="x.com"),
_expect(fn=1),
id="optional-union",
),
pytest.param(
ListArmUnionHolder,
ListArmUnionElement,
Search(query="hotels"),
Browse(url="x.com"),
_expect(fn=1),
id="union-with-list-arm",
),
pytest.param(
ListArmAnyHolder,
ListArmAnyElement,
Inner(a="x", b="y"),
Other(c="z"),
_expect(fn=2),
id="any-with-list-arm",
),
],
)
def test_another_class_in_a_nested_or_list_sub_field_counts_as_top_level(
holder, element, gt, pred, aggregate
):
# A field routed as a nested model, or annotated as a list, sends every
# pair to the dispatcher, so the pair is a TP and its leaves report the
# fields the prediction lacks, as at top level (#327).
node = _value_node(_in_list(gt, pred, holder=holder, element=element))
assert _counts(node) == _expect(tp=1)
assert _counts(node, "aggregate") == aggregate

with warnings.catch_warnings():
warnings.simplefilter("ignore")
alone = element(key="k", value=gt).compare_with(
element(key="k", value=pred), include_confusion_matrix=True
)
top = alone["confusion_matrix"]["fields"]["value"]
assert _counts(top) == _expect(tp=1)
assert _counts(top, "aggregate") == aggregate


def _pairs_in_list(gts, preds, holder=Holder, element=Element):
def items(values):
return [element(key=f"k{i}", value=v) for i, v in enumerate(values)]
Expand Down