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): widen the CHANGELOG and tests to every path the guard covers
The crash is not Any-only: a Union sub-field, or a Dict one with an explicit
LevenshteinComparator, raised too. bytes, arbitrary objects and plain pydantic
models under a refused comparator also moved from TP to FD. Adds those cases,
a whitespace-vs-None case, and a check that the counts now agree with
non_matches.
  • Loading branch information
sromoam committed Oct 15, 2026
commit e7810fa5a3edeaf8a8a103fbf6782f4d8f50580d
15 changes: 10 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,16 @@ Each release links to full notes on the

- **Breaking:** a primitive sub-field of a `List[StructuredModel]` element is
now classified as it is at top level. Its confusion-matrix counts called the
field's comparator directly, skipping the dispatcher's guards, so a dict in an
`Any` sub-field raised `TypeError` out of `compare_with()` instead of warning
and scoring an FD. Counts move for working inputs too, though scores do not:
- with an inferred comparator, a tuple, a set, or a `date` against its ISO
string is an FD, not a TP the item's score did not credit;
field's comparator directly, skipping the dispatcher's guards, so a dict its
comparator cannot score (in an `Any` or `Union` sub-field, or a `Dict` one
with an explicit `LevenshteinComparator`) raised `TypeError` out of
`compare_with()` instead of warning and scoring an FD. Counts move for working
inputs too, though scores do not, and now agree with `non_matches`:
- a pair the comparator is not given at top level is an FD, not a TP the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: the Breaking entry leaves out several count changes, so consumers who re-baseline from it will be surprised.

With value: Any, the entry covers only the both-empty pair. It omits:

  • (), set() or b'' vs None: TN becomes FN.
  • None vs (): TN becomes FA.
  • null vs [], and [] vs [] (see line 553).
  • The model-valued Any/Union changes: FD to TP and TP to FD, including wrong-class pairs.

The PR description says None and "" "count as before", which is false against [].

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rewrote the entry around the rule rather than a list of inputs (e2d3287). A list element's sub-field is now classified by the same dispatcher as a top-level field, so its counts match top level, apart from four cases, and scores don't change. The list path skipped the dispatcher for any sub-field it didn't route as a nested model or a list: Any, object, Union[A, B], Dict and str, and also spellings such as Sequence[str], Sequence[Inner] and Optional[Annotated[Inner, Field(...)]]. Earlier versions tried to list every input that moves, and kept missing some, such as a Decimal or UUID against its string, two Enum classes, Inner against [Inner], or frozenset() against None. Their "count as before" sentence was also false for the Sequence and Annotated spellings, which now count as at top level. The bullets are now examples:

  • a dict the comparator can't score raised TypeError, and now warns and counts an FD;
  • a pair top level doesn't give the comparator is an FD, not a TP the score didn't credit: a tuple, a Decimal or UUID against its string, two Enum classes, Inner(a="x") against [Inner(a="x")];
  • a value top level doesn't read as null, such as (), frozenset(), b" " or " ", is no longer a TN against a null one;
  • two lists count per element, and a list of models keeps its fields, in Any or Sequence[...] alike;
  • a model of the GT's class takes its verdict from the item's score for the field, so Inner(a="hotel") vs Inner(a="hotels") at 0.9 is an FD in Any or Optional[Annotated[Inner, Field(...)]], as it already was in Optional[Inner];
  • a union field two classes declare differently follows the first matched GT element that declares it, so with a str-typed class first, a list-annotated field of another class now counts per element, as in the other order.

eeb73f9 and 9f85e15 pin the Sequence and Annotated rows, each against top level. The entry still names the AttributeError crash and its shapes, the object-level TP those pairs count, the fixed-score override rows (why most are TPs, and the shapes the dispatcher raises on, which keep dev's count: two lists, one FD from the comparator, cd3fb59, and two models of one class whose own compare_with() also returns a fixed score, such as Leaf(d=[Inner(a="x")]) against Leaf(d=[Point(x=1)]), one TP from that compare_with(), 823c451; a list-annotated sub-field such as List[Any] falls back the same way when the list's first element's class doesn't declare it as a list, efa47ca), the plain pydantic TypeError, and the ground-truth raise that remains, next to the one that was fixed. It lists the four cases that still differ from top level. Two apply to every sub-field. An extra field on the prediction, one its class doesn't declare, isn't counted, where top level counts an FA (5654027). A sub-field that mixes models with None across pairs keeps one shape under aggregate: one read by value keeps every pair as one leaf, and one that goes to the dispatcher directly, such as Optional[Inner], keeps the models' fields and leaves the None pair out, as on dev (7b8841c). fac2680 and 780c213 pin both. The other two apply to a sub-field not routed as a nested model or a list: a model of another class (with its TPs, Pet vs Cat and Inner(a="x") vs Other(c="z") at the default threshold), and an empty list read as null. The "Nested lists" note in classification-logic.md now says the same, and names by example which fields go to the dispatcher directly and which are read by value first (5814586). The entry also says that under a fixed-score element every sub-field now gets the dispatcher's warnings, as without the override, so a filterwarnings = error run raises there, where dev was silent (a5e8aa0, 9ab8ec9, pinned in f1aa451 and dfc5cc1). overall_score is unchanged in every row that ran on dev.

The entry is under Fixed now, not Breaking (1f0973d), and I've dropped the ! from the title. The project counts as breaking only an API change: a public name, parameter or result field, a default, input the docs accept that is now rejected, or a documented output format. This entry changes none of those. On input that ran on dev, every overall count it moves now matches top level and the item's own field score, with one exception: the empty-list rule the classification docs give for a sub-field read by value. Such a sub-field reads [] and [None] as null, so " ", (), set() or b"" against [] is an FN (the reverse an FA), where top level gives an FD. aggregate follows the documented mixed-shapes rule. Where the dispatcher can score them, the fixed-score override rows now count what the same pairs count without the override and at top level, which follows the field-by-field scoring StructuredModel still uses for objects of different classes, as the entry says. Where it raises, they keep dev's count. The one new raise is the dispatcher's warning under a fixed-score element, and only under warnings as errors. I've also updated the PR description. On the head you reviewed, it was wrong about None and "" against [], and its [] vs [] row and overlap section were stale.

item's score did not credit (a TN if empty). With an inferred comparator
that is a tuple, a set, `bytes`, an arbitrary object, or a `date` against
its ISO string; under `LevenshteinComparator`, a plain pydantic model;
under `FuzzyComparator` or `NormalizedComparator`, that or a dict;
- a list in an `Any` sub-field counts one per element, not one in total;
- a whitespace-only string is a value, not null
([#400](https://github.com/awslabs/stickler/issues/400))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,8 @@ def _handle_non_hierarchical_field(

# Classify through the dispatcher, as the branches above do, so
# a sub-field counts the way it does outside a list. Calling the
# comparator directly skipped its guards, so a dict in an `Any`
# sub-field raised instead of scoring an FD (#400).
# comparator directly skipped its guards, so a dict it cannot
# score raised instead of scoring an FD (#400).
field_classification = gt_item._dispatch_field_comparison(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocker: routing through the dispatcher changes empty-list counts, and wrong-class predictions now count as TP.

Empty lists. For Element.value: Any inside Holder.items: List[Element]:

  • None vs [] moves from TN to FA.
  • [] vs None moves from TN to FN.
  • '', {} or NaN vs [] moves from TN to FA.
  • [] vs [] and [None] vs [None] move from TN to no count at all.

This contradicts classification-logic.md lines 41, 56 and 193. Dispatcher STEP 3 applies list null handling only when the annotation is a list. STEP 4 does not treat [] as null. PrimitiveListComparator hard-codes tn: 0.

Wrong-class predictions. A StructuredModel in an Any/Union sub-field is now judged by compare() (dispatcher CASE 3, field_comparator.py:136) instead of by compare_with()['overall_score']. With value: Union[Search, Browse] = ComparableField(threshold=0.9), a GT Search(...) against a predicted Browse(...) moves from FD to TP, while non_matches still reports items[0].value.query as a false negative. #327 (classification-logic.md:125) says different classes are always FD. Inner(a, b) vs Other(c) also becomes TP, because compare() returns 1.0 when the two share no field.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed on both, thanks.

Empty lists. In a sub-field the list path reads by value, such as Any, object or Sequence[str], the list path reads an empty list as null by its value (2c43b0e, scoped in 0a52737). Every row you listed is a TN again: None, "", {} or NaN vs [], [] vs None, [] vs [], and [None] vs [None]. "x" vs [] is an FN. All of these are as on dev, and 992fc09 pins them. One kind of row against [] does move. A value top level doesn't read as null, such as " ", (), frozenset() or b" ", is not null here either, so " " vs [] is now an FN (the reverse an FA), not a TN, as it is against None, "", {} or NaN. The CHANGELOG gives it as an example of the rule, and bfea4ad and 776449e pin it. When both sides are lists, they still go to the list comparator, which counts one per element. Sub-fields annotated as a list, such as List[str] or Union[str, List[str]], go straight to the dispatcher, as on dev. Sequence[str] isn't one of them: it's read by value, so two lists there now count per element too, as at top level (eeb73f9). A top-level Any or object field still reads [] as a value, so None vs [] is an FA there, and non_matches reads it the same way, also in a list element. Fixing that moves top-level scores, so I'll do it in the dispatcher and non_matches, tracked as a follow-up for 1.1.0. The classification docs and the CHANGELOG list it as a known difference.

Wrong class. ad608ac goes back to dev's rule. In an Any, object or Union[A, B] sub-field, two models of different classes are one TP or FD, from the GT model's compare_with() score against the field's threshold, with no subtree. Your Search vs Browse pair at threshold 0.9 is an FD again, and so is Inner(a, b="y") vs Other(c). The item's score for the field is still 1.0, because compare() skips the fields the prediction lacks. Fixing that stays with #327.

That rule still gives two TPs, both as on dev. compare_with() reads a field the prediction lacks as None, so an unset GT field matches it: Inner(a="x") vs Other(c="z") scores 0.5, from b, and is a TP at the default threshold of 0.5. It also scores only the GT's own fields, so Pet(tom) vs Cat(tom, 9) is a TP. The classification docs and the CHANGELOG name both, and f17b715 and ad608ac pin them.

An Optional union of models, or a union with a list arm, went through the dispatcher on dev and still does (95f16be). There Search vs Browse counts as at top level: a TP, with query 1 FN under aggregate.

sub_field_name, gt_sub_value, pred_sub_value
)["overall"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: keeping only ['overall'] drops the fields subtree the dispatcher returns for model-valued sub-fields, so aggregate still differs from the top level.

For the wrong-class Union pair, aggregate for value is tp1 on the list path, but tp3 fn1 at the top level. Inner(a, b) vs Other(c) gives tp1 vs fn2. The is_simple_list branch at lines 516-537 already keeps the subtree with _recursive_aggregate_metrics. Using that loop for both branches made aggregate match the top level in every model-valued case, and the other 76 scenarios were unchanged.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 2c43b0e. Both branches now share the per-pair loop and _recursive_aggregate_metrics. So in an Any, object or Union[A, B] sub-field, a model of the GT's class keeps its fields under aggregate, as at top level: Inner(a="x", b="y") vs itself gives 2 TP, where dev gave 1. test_a_model_in_a_sub_field_keeps_its_leaves checks the list path and top level against the same literal counts.

Your two wrong-class pairs are the exception. They're back to dev's rule (thread 2), so each is one FD with no subtree, and their aggregate is 1 FD rather than top level's TP with FNs. The classification docs list this as a difference.

I also added a guard in 0999f7a. aggregate sums a node's children when it has any, so when one pair kept a model's fields, a pair holding None or a primitive dropped out. The node now keeps its subtree only when every pair has one. So [Inner(x), Inner(y)] vs [Inner(x), None] gives root aggregate 3 TP and 1 FN in an Any or object sub-field, and ["abc", Inner] vs itself gives 4 TP, both as on dev. test_a_sub_field_of_mixed_shapes_counts_every_pair pins them. A nested-model or list-annotated sub-field, such as Optional[Inner], still leaves such pairs out, as on dev: those pairs give that sub-field aggregate 1 TP and 1 TN, where top level gives 1 TP, 1 TN and 1 FN. The classification docs and the CHANGELOG say so (7b8841c), and fac2680 pins it for Optional[Inner], Inner | None, Annotated[Optional[Inner], Field(...)] and Optional[List[Inner]]. It is tracked as a follow-up for 1.1.0.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
counted a primitive sub-field by calling the field's comparator directly, not
through `_dispatch_field_comparison`. That skipped the dispatcher's guards, so:

- a dict in an `Any` sub-field raised `TypeError` out of `compare_with()`, where
the same field at top level warns and scores an FD;
- a tuple, a set, or a `date` against its ISO string counted a TP that the
item's score did not credit;
- a dict the field's comparator cannot score raised `TypeError` out of
`compare_with()`, where the same field at top level warns and scores an FD;
- a pair the comparator is not given at top level (with an inferred
comparator, a tuple, a set, `bytes`, or a `date` against its ISO string; a
plain pydantic model under `LevenshteinComparator`) counted a TP that the
item's score did not credit, and that `non_matches` reported as an FD;
- a list in an `Any` sub-field counted one unit instead of one per element;
- a whitespace-only string counted as null.

Expand All @@ -17,11 +19,17 @@

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

import pytest
from pydantic import BaseModel

from stickler import ComparableField, StructuredModel
from stickler import (
ComparableField,
LevenshteinComparator,
NonMatchType,
StructuredModel,
)

COUNTS = ("tp", "fa", "fd", "fp", "tn", "fn")

Expand All @@ -40,6 +48,20 @@ class Flat(StructuredModel):
value: Any = ComparableField()


class MappingElement(StructuredModel):
key: str = ComparableField(threshold=1.0)
value: Dict[str, str] = ComparableField(comparator=LevenshteinComparator())
match_threshold = 0.4


class MappingHolder(StructuredModel):
items: List[MappingElement] = ComparableField()


class Point(BaseModel):
x: int


def _counts(node):
return {k: node["overall"][k] for k in COUNTS}

Expand All @@ -51,10 +73,15 @@ def _top_level(gt, pred):
return _counts(result["confusion_matrix"]["fields"]["value"])


def _in_list(gt, pred):
result = Holder(items=[Element(key="k", value=gt)]).compare_with(
Holder(items=[Element(key="k", value=pred)]), include_confusion_matrix=True
def _in_list(gt, pred, **kwargs):
return Holder(items=[Element(key="k", value=gt)]).compare_with(
Holder(items=[Element(key="k", value=pred)]),
include_confusion_matrix=True,
**kwargs,
)


def _in_list_counts(result):
items = result["confusion_matrix"]["fields"]["items"]
return _counts(items["fields"]["value"])

Expand All @@ -66,24 +93,60 @@ def _in_list(gt, pred):
pytest.param({"text": "p"}, {"text": "p"}, id="identical-dict"),
pytest.param(("a", "b"), ("a", "c"), id="tuple"),
pytest.param({"a"}, {"b"}, id="set"),
pytest.param(b"ab", b"ab", id="bytes"),
pytest.param(Point(x=1), Point(x=2), id="plain-model"),
pytest.param(datetime.date(2020, 1, 1), "2020-01-01", id="date-vs-str"),
pytest.param(["a", "b"], ["a", "c"], id="list"),
pytest.param(["a", "b"], ["b", "a"], id="reordered-list"),
pytest.param(" ", "x", id="whitespace"),
pytest.param(" ", None, id="whitespace-vs-none"),
pytest.param("abc", "abd", id="str"),
pytest.param(None, "x", id="none-vs-str"),
],
)
def test_sub_field_counts_as_at_top_level(gt, pred):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
assert _in_list(gt, pred) == _top_level(gt, pred)
assert _in_list_counts(_in_list(gt, pred)) == _top_level(gt, pred)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: the parity assertion compares two calls into the same dispatch_field_comparison, so it passes whatever the dispatcher returns.

On head, the list-path counts equalled the top-level counts in all 82 scenarios, including None vs [] (FA), [] vs [] (no count) and the wrong-class Union pair (TP). Pin expected counts for the empty-list and model-valued rows.

Separately, and lower priority: #398 and #399 have both merged, so StructuredModel._classify_field_for_confusion_matrix, ConfusionMatrixCalculator.classify_field_for_confusion_matrix, TestVerdictShape, and the stale module docstring in test_list_subfield_classification.py can be deleted in this PR, as its description planned.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, it couldn't fail. 992fc09 pins literal counts in every row. Later commits add rows for other-class models, mixed shapes across pairs, a list against None, nested and list-annotated sub-fields whose counts don't move, Sequence[...] and Optional[Annotated[Inner, Field(...)]] sub-fields, which now count as at top level, object sub-fields, the fixed-score override rows (including the two-list shapes that keep dev's FD, two models of one class that keep dev's TP, list sub-fields the first element's class doesn't route as a list, and the dispatcher's warnings), a union field two classes declare differently, mixed shapes in a sub-field that goes to the dispatcher directly, an extra field on a predicted element, and the CHANGELOG's examples. None vs [] and [] vs [] are pinned at TN, as the classification docs say, and a whitespace string or empty tuple against a null value at FN. Inner(a, b) vs Other(c) and Search vs Browse in Any, object and Union[A, B] are pinned at FD, as on dev, and Inner(a="x") vs Other(c="z") at the default threshold at TP. Of the 238 tests, 113 fail on dev, 144 on the pre-fix merge e2377a5, and 144 on the pushed head 3145138. The 43 that pass on all three pin dev behaviour the docs now name. Since #398 and #399 are in, e30e6be also deletes the classifier (and with it confusion_matrix_calculator.py), its StructuredModel wrapper and TestVerdictShape, and it rewrites the stale module docstring. The deletion has no CHANGELOG entry, because all of it is private: the classifier and its wrapper are underscore methods, and the module is not exported. The earlier removals of uncalled private wrappers, three in #390 and one in #398, had none either. docs/structured_model_REFACTORING.md records it next to them. 15ffdc2 brings back only the classifier's list branch, as _comparator_result, for the one path that still needs it: two lists the dispatcher raises on, which only a fixed-score element reaches. ff33e1b likewise counts two models of one class the dispatcher raises on from the GT model's compare_with() (_compare_with_result), and b9ab522 extends both fallbacks to a list-annotated sub-field the list's first element's class doesn't route as a list. They are private too, and the CHANGELOG describes its effect, not the helper.



@pytest.mark.parametrize(
"gt, pred, expected",
[
pytest.param(("a", "b"), ("a", "b"), NonMatchType.FALSE_DISCOVERY, id="tuple"),
pytest.param(" ", "x", NonMatchType.FALSE_DISCOVERY, id="whitespace"),
pytest.param(" ", None, NonMatchType.FALSE_NEGATIVE, id="whitespace-vs-none"),
],
)
def test_sub_field_counts_agree_with_non_matches(gt, pred, expected):
result = _in_list(gt, pred, document_non_matches=True)

reported = [
n["non_match_type"]
for n in result["non_matches"]
if n["field_path"] == "items[0].value"
]
assert reported == [expected]
count = {
NonMatchType.FALSE_DISCOVERY: "fd",
NonMatchType.FALSE_NEGATIVE: "fn",
}[expected]
assert _in_list_counts(result)[count] == 1


@pytest.mark.parametrize("include_confusion_matrix", [False, True])
def test_dict_in_any_sub_field_warns_instead_of_raising(include_confusion_matrix):
gt = Holder(items=[Element(key="k", value={"text": "p"})])
pred = Holder(items=[Element(key="k", value={"text": "q"})])
@pytest.mark.parametrize(
"holder, element",
[
pytest.param(Holder, Element, id="any"),
pytest.param(MappingHolder, MappingElement, id="dict-explicit-levenshtein"),
],
)
def test_dict_in_sub_field_warns_instead_of_raising(
holder, element, include_confusion_matrix
):
gt = holder(items=[element(key="k", value={"text": "p"})])
pred = holder(items=[element(key="k", value={"text": "q"})])

with pytest.warns(UserWarning, match="holds a mapping"):
result = gt.compare_with(
Expand Down
Loading