value-semantics-core 2.2.0__tar.gz → 2.3.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/PKG-INFO +1 -1
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/pyproject.toml +1 -1
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/tests/test_figure_statement.py +240 -17
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core/__init__.py +28 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core/figure_statement.py +426 -30
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core.egg-info/PKG-INFO +1 -1
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/README.md +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/setup.cfg +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/tests/test_comps_manifest_display.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/tests/test_enterprise_value.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/tests/test_forward_ev_adjusted_ebitda.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/tests/test_forward_pe.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/tests/test_ntm_forward_ev_adjusted_ebitda.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/tests/test_ntm_forward_pe.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/tests/test_numeric_display.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/tests/test_two_stage_reconciliation.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core/comps_manifest_display.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core/conventions_ir_v1.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core/decimal_wire.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core/enterprise_value.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core/formatting.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core/forward_ev_adjusted_ebitda.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core/forward_pe.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core/numeric_display.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core/period_ref.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core/quantity.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core/reconciliation.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core.egg-info/SOURCES.txt +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core.egg-info/dependency_links.txt +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core.egg-info/requires.txt +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core.egg-info/top_level.txt +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "value-semantics-core"
|
|
7
|
-
version = "2.
|
|
7
|
+
version = "2.3.1"
|
|
8
8
|
description = "Shared value-semantics types and canonical numeric conventions"
|
|
9
9
|
requires-python = ">=3.10"
|
|
10
10
|
dependencies = ["pydantic>=2.12,<3"]
|
|
@@ -16,14 +16,18 @@ from value_semantics_core.figure_statement import (
|
|
|
16
16
|
FigureStatementInvalid,
|
|
17
17
|
FiscalPeriod,
|
|
18
18
|
InlineStatement,
|
|
19
|
+
PRODUCT_STATEMENT_MEASURE_KINDS,
|
|
19
20
|
PlaceKey,
|
|
21
|
+
SkillArtifactMeasure,
|
|
20
22
|
StatementsRefused,
|
|
21
23
|
TrailingPeriod,
|
|
24
|
+
VENDOR_FIELD_CLASSIFICATIONS,
|
|
22
25
|
VendorMeasure,
|
|
23
26
|
expand_place_key,
|
|
24
27
|
expand_same_as_figure,
|
|
25
28
|
figure_places,
|
|
26
29
|
figure_statement_vocabulary,
|
|
30
|
+
is_product_statement_measure_kind,
|
|
27
31
|
not_stated,
|
|
28
32
|
parse_figure_statement,
|
|
29
33
|
parse_statements,
|
|
@@ -32,7 +36,9 @@ from value_semantics_core.figure_statement import (
|
|
|
32
36
|
render_statement_label,
|
|
33
37
|
render_statements,
|
|
34
38
|
resolve_statements,
|
|
39
|
+
statement_measure_kinds,
|
|
35
40
|
trailing_alignment,
|
|
41
|
+
validate_statement_entries,
|
|
36
42
|
)
|
|
37
43
|
|
|
38
44
|
|
|
@@ -57,7 +63,7 @@ def _resolve(case: dict) -> dict:
|
|
|
57
63
|
|
|
58
64
|
|
|
59
65
|
def test_fixture_version_and_vocabulary() -> None:
|
|
60
|
-
assert FIXTURE["fixture_version"] ==
|
|
66
|
+
assert FIXTURE["fixture_version"] == 6
|
|
61
67
|
assert FIXTURE["vocabulary"] == figure_statement_vocabulary()
|
|
62
68
|
|
|
63
69
|
|
|
@@ -119,12 +125,27 @@ def test_refused_patterns(pattern: list) -> None:
|
|
|
119
125
|
# --- the statement ----------------------------------------------------------
|
|
120
126
|
|
|
121
127
|
|
|
122
|
-
def
|
|
128
|
+
def test_basis_is_required_and_not_stated_basis_round_trips() -> None:
|
|
123
129
|
wire = _statement("vendor_trailing_ratio_periods_not_recorded")
|
|
124
|
-
assert set(wire) == {"measure", "period"}
|
|
130
|
+
assert set(wire) == {"measure", "period", "basis"}
|
|
125
131
|
statement = parse_figure_statement(wire)
|
|
126
|
-
assert statement.basis
|
|
127
|
-
assert "basis"
|
|
132
|
+
assert statement.basis == not_stated("vendor_figure_not_compared_to_filing")
|
|
133
|
+
assert render_figure_statement(statement)["basis"] == {
|
|
134
|
+
"kind": "not_stated",
|
|
135
|
+
"reason": "vendor_figure_not_compared_to_filing",
|
|
136
|
+
}
|
|
137
|
+
missing = copy.deepcopy(wire)
|
|
138
|
+
missing.pop("basis")
|
|
139
|
+
with pytest.raises(FigureStatementInvalid) as raised:
|
|
140
|
+
parse_figure_statement(missing)
|
|
141
|
+
assert raised.value.field == "basis"
|
|
142
|
+
|
|
143
|
+
not_recorded = copy.deepcopy(_statement("issuer_filed_fiscal_year_with_basis"))
|
|
144
|
+
not_recorded["basis"] = {"kind": "not_stated", "reason": "basis_not_recorded"}
|
|
145
|
+
parsed_not_recorded = parse_figure_statement(not_recorded)
|
|
146
|
+
assert parsed_not_recorded.basis == not_stated("basis_not_recorded")
|
|
147
|
+
assert render_figure_statement(parsed_not_recorded) == not_recorded
|
|
148
|
+
assert render_statement_label(not_recorded).endswith("; basis not recorded")
|
|
128
149
|
|
|
129
150
|
|
|
130
151
|
def test_a_statement_built_in_code_renders_the_fixture() -> None:
|
|
@@ -139,6 +160,7 @@ def test_a_statement_built_in_code_renders_the_fixture() -> None:
|
|
|
139
160
|
kind="trailing", end_date=not_stated("end_date_not_recorded"), status="actual",
|
|
140
161
|
periods_summed=not_stated("periods_not_recorded"),
|
|
141
162
|
),
|
|
163
|
+
basis=not_stated("vendor_figure_not_compared_to_filing"),
|
|
142
164
|
)
|
|
143
165
|
assert render_figure_statement(statement) == _statement("vendor_trailing_ratio_periods_not_recorded")
|
|
144
166
|
|
|
@@ -367,7 +389,7 @@ def test_only_an_input_is_tagged_never_a_figures_own_statement() -> None:
|
|
|
367
389
|
parse_figure_statement({**wire, "kind": "statement"})
|
|
368
390
|
with pytest.raises(StatementsRefused) as raised:
|
|
369
391
|
resolve_statements(
|
|
370
|
-
[{"at": ["v"], "measure": wire["measure"], "period": wire["period"], "kind": "statement"}],
|
|
392
|
+
[{"at": ["v"], "measure": wire["measure"], "period": wire["period"], "basis": wire["basis"], "kind": "statement"}],
|
|
371
393
|
{"v": 1.0},
|
|
372
394
|
)
|
|
373
395
|
assert raised.value.code == "unknown_key"
|
|
@@ -406,14 +428,15 @@ def test_an_entry_at_a_row_states_every_number_in_it_unless_excluded() -> None:
|
|
|
406
428
|
def test_place_key_is_the_field_only_and_a_bare_missing_field_stays_refused() -> None:
|
|
407
429
|
measure = CASES["vendor_ratios_ttm_one_entry_place_key"]["statements"][0]["measure"]
|
|
408
430
|
period = CASES["vendor_ratios_ttm_one_entry_place_key"]["statements"][0]["period"]
|
|
431
|
+
basis = CASES["vendor_ratios_ttm_one_entry_place_key"]["statements"][0]["basis"]
|
|
409
432
|
for changed in (
|
|
410
433
|
{key: value for key, value in measure.items() if key != "field"},
|
|
411
434
|
{**measure, "endpoint": {"kind": "place_key"}},
|
|
412
435
|
{**measure, "field": {"kind": "place_key", "at": -1}},
|
|
413
436
|
):
|
|
414
437
|
with pytest.raises(FigureStatementInvalid):
|
|
415
|
-
parse_figure_statement({"measure": changed, "period": period})
|
|
416
|
-
statement = parse_figure_statement({"measure": measure, "period": period})
|
|
438
|
+
parse_figure_statement({"measure": changed, "period": period, "basis": basis})
|
|
439
|
+
statement = parse_figure_statement({"measure": measure, "period": period, "basis": basis})
|
|
417
440
|
with pytest.raises(FigureStatementInvalid):
|
|
418
441
|
expand_place_key(statement, ["closes", 0])
|
|
419
442
|
|
|
@@ -514,6 +537,7 @@ def _nested_place(place: list, period: dict | None = None) -> dict:
|
|
|
514
537
|
"measure": {"kind": "computed", "operation": "sum", "parameters": {},
|
|
515
538
|
"inputs": [{"kind": "place", "place": place}]},
|
|
516
539
|
"period": period or {"kind": "same_as_figure"},
|
|
540
|
+
"basis": {"kind": "not_stated", "reason": "basis_not_recorded"},
|
|
517
541
|
}
|
|
518
542
|
|
|
519
543
|
|
|
@@ -536,12 +560,13 @@ def test_a_nested_input_is_held_to_the_status_of_the_statement_that_lists_it() -
|
|
|
536
560
|
vendor = {"kind": "vendor", "provider": "fmp", "endpoint": "ratios_ttm", "field": "x",
|
|
537
561
|
"definition": {"kind": "not_stated", "reason": "definition_not_recorded"},
|
|
538
562
|
"classification": {"kind": "not_stated", "reason": "classification_not_recorded"}}
|
|
563
|
+
unrecorded_basis = {"kind": "not_stated", "reason": "basis_not_recorded"}
|
|
539
564
|
|
|
540
565
|
def statements(inline: dict) -> list[dict]:
|
|
541
566
|
return [
|
|
542
|
-
{"at": ["comparison", 0], "period": projected, "measure": {
|
|
567
|
+
{"at": ["comparison", 0], "period": projected, "basis": unrecorded_basis, "measure": {
|
|
543
568
|
"kind": "computed", "operation": "ratio", "parameters": {}, "inputs": [inline]}},
|
|
544
|
-
{"at": ["comparison", 1], "measure": vendor, "period": projected},
|
|
569
|
+
{"at": ["comparison", 1], "measure": vendor, "period": projected, "basis": unrecorded_basis},
|
|
545
570
|
]
|
|
546
571
|
|
|
547
572
|
# A projected figure; its inline operand holds the figure's status through same_as_figure.
|
|
@@ -559,12 +584,18 @@ def test_a_projected_inline_input_under_an_actual_figure_is_refused_at_any_depth
|
|
|
559
584
|
vendor = {"kind": "vendor", "provider": "fmp", "endpoint": "ratios_ttm", "field": "x",
|
|
560
585
|
"definition": {"kind": "not_stated", "reason": "definition_not_recorded"},
|
|
561
586
|
"classification": {"kind": "not_stated", "reason": "classification_not_recorded"}}
|
|
587
|
+
unrecorded_basis = {"kind": "not_stated", "reason": "basis_not_recorded"}
|
|
562
588
|
|
|
563
589
|
def computed(*inputs: dict) -> dict:
|
|
564
590
|
return {"kind": "computed", "operation": "sum", "parameters": {}, "inputs": list(inputs)}
|
|
565
591
|
|
|
566
592
|
def inline(measure: dict, period: dict | None = None) -> dict:
|
|
567
|
-
return {
|
|
593
|
+
return {
|
|
594
|
+
"kind": "statement",
|
|
595
|
+
"measure": measure,
|
|
596
|
+
"period": period or {"kind": "same_as_figure"},
|
|
597
|
+
"basis": unrecorded_basis,
|
|
598
|
+
}
|
|
568
599
|
|
|
569
600
|
forecast = inline(vendor, projected)
|
|
570
601
|
one_down = computed(inline(computed(forecast)))
|
|
@@ -573,12 +604,12 @@ def test_a_projected_inline_input_under_an_actual_figure_is_refused_at_any_depth
|
|
|
573
604
|
for measure in (one_down, two_down):
|
|
574
605
|
# The operand between them takes the figure's period, so the figure's status holds the forecast.
|
|
575
606
|
with pytest.raises(FigureStatementInvalid, match="projected input"):
|
|
576
|
-
parse_figure_statement({"measure": measure, "period": actual})
|
|
607
|
+
parse_figure_statement({"measure": measure, "period": actual, "basis": unrecorded_basis})
|
|
577
608
|
with pytest.raises(StatementsRefused) as raised:
|
|
578
|
-
resolve_statements([{"at": ["value"], "measure": measure, "period": actual}], {"value": 1.0})
|
|
609
|
+
resolve_statements([{"at": ["value"], "measure": measure, "period": actual, "basis": unrecorded_basis}], {"value": 1.0})
|
|
579
610
|
assert raised.value.code == "statement_invalid"
|
|
580
611
|
# A projected figure may be computed from the same forecast.
|
|
581
|
-
parsed = parse_figure_statement({"measure": measure, "period": projected})
|
|
612
|
+
parsed = parse_figure_statement({"measure": measure, "period": projected, "basis": unrecorded_basis})
|
|
582
613
|
assert parse_figure_statement(render_figure_statement(parsed)) == parsed
|
|
583
614
|
# What is admitted is admitted in its resolved form too: the one parse reads what expansion writes.
|
|
584
615
|
expanded = render_figure_statement(expand_same_as_figure(parsed))
|
|
@@ -589,12 +620,12 @@ def test_a_projected_inline_input_under_an_actual_figure_is_refused_at_any_depth
|
|
|
589
620
|
# computed from a forecast.
|
|
590
621
|
under_projected = computed(inline(computed(inline(vendor)), actual))
|
|
591
622
|
with pytest.raises(FigureStatementInvalid, match="projected input"):
|
|
592
|
-
parse_figure_statement({"measure": under_projected, "period": projected})
|
|
623
|
+
parse_figure_statement({"measure": under_projected, "period": projected, "basis": unrecorded_basis})
|
|
593
624
|
with pytest.raises(StatementsRefused) as raised:
|
|
594
|
-
resolve_statements([{"at": ["value"], "measure": under_projected, "period": projected}], {"value": 1.0})
|
|
625
|
+
resolve_statements([{"at": ["value"], "measure": under_projected, "period": projected, "basis": unrecorded_basis}], {"value": 1.0})
|
|
595
626
|
assert raised.value.code == "statement_invalid"
|
|
596
627
|
# The same operand under an actual figure reads the figure's actual period and is admitted.
|
|
597
|
-
admitted = parse_figure_statement({"measure": under_projected, "period": actual})
|
|
628
|
+
admitted = parse_figure_statement({"measure": under_projected, "period": actual, "basis": unrecorded_basis})
|
|
598
629
|
expanded = render_figure_statement(expand_same_as_figure(admitted))
|
|
599
630
|
assert render_figure_statement(parse_figure_statement(expanded)) == expanded
|
|
600
631
|
|
|
@@ -675,3 +706,195 @@ def test_a_stale_exception_in_not_figures_is_refused() -> None:
|
|
|
675
706
|
case["statements"], case["result"], not_figures=[["data", None, {"except": ["mktCap"]}]]
|
|
676
707
|
)
|
|
677
708
|
assert raised.value.code == "pattern_matches_nothing"
|
|
709
|
+
|
|
710
|
+
|
|
711
|
+
def test_skill_artifact_and_product_statement_measure_vocabulary() -> None:
|
|
712
|
+
assert VENDOR_FIELD_CLASSIFICATIONS == (
|
|
713
|
+
"filing_line",
|
|
714
|
+
"aggregate_derivation",
|
|
715
|
+
"vendor_convenience",
|
|
716
|
+
"market_observation",
|
|
717
|
+
)
|
|
718
|
+
assert PRODUCT_STATEMENT_MEASURE_KINDS == frozenset(
|
|
719
|
+
{"product_model", "skill_artifact", "computed"}
|
|
720
|
+
)
|
|
721
|
+
for kind in ("product_model", "skill_artifact", "computed"):
|
|
722
|
+
assert is_product_statement_measure_kind(kind) is True
|
|
723
|
+
for kind in ("issuer_filed", "vendor", "broker_reported", None, 123, True):
|
|
724
|
+
assert is_product_statement_measure_kind(kind) is False
|
|
725
|
+
|
|
726
|
+
verdict_wire = _statement("skill_artifact_verdict_figure")
|
|
727
|
+
parsed = parse_figure_statement(verdict_wire)
|
|
728
|
+
assert isinstance(parsed.measure, SkillArtifactMeasure)
|
|
729
|
+
assert parsed.measure.field == "verdict.composite"
|
|
730
|
+
assert render_figure_statement(parsed) == verdict_wire
|
|
731
|
+
|
|
732
|
+
whole_wire = _statement("skill_artifact_whole_row")
|
|
733
|
+
parsed_whole = parse_figure_statement(whole_wire)
|
|
734
|
+
assert isinstance(parsed_whole.measure, SkillArtifactMeasure)
|
|
735
|
+
assert parsed_whole.measure.field is None
|
|
736
|
+
assert "field" not in render_figure_statement(parsed_whole)["measure"]
|
|
737
|
+
|
|
738
|
+
for bad_measure in (
|
|
739
|
+
{**verdict_wire["measure"], "field": None},
|
|
740
|
+
{**verdict_wire["measure"], "field": " "},
|
|
741
|
+
{**verdict_wire["measure"], "skill": ""},
|
|
742
|
+
{**verdict_wire["measure"], "content_sha256": "not-a-sha256"},
|
|
743
|
+
):
|
|
744
|
+
with pytest.raises(FigureStatementInvalid):
|
|
745
|
+
parse_figure_statement({**verdict_wire, "measure": bad_measure})
|
|
746
|
+
|
|
747
|
+
|
|
748
|
+
@pytest.mark.parametrize("name", sorted(CASES))
|
|
749
|
+
def test_validate_statement_entries_accepts_every_fixture_case_without_result(name: str) -> None:
|
|
750
|
+
entries = validate_statement_entries(copy.deepcopy(CASES[name]["statements"]))
|
|
751
|
+
assert render_statements(entries) == CASES[name]["statements"]
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
@pytest.mark.parametrize(
|
|
755
|
+
("name", "expected_code"),
|
|
756
|
+
[
|
|
757
|
+
("conflicting_key_in_measure", "conflicting_facts"),
|
|
758
|
+
("conflicting_basis", "conflicting_facts"),
|
|
759
|
+
("a_figure_whose_basis_is_not_stated", "figure_not_stated"),
|
|
760
|
+
("unknown_entry_key", "unknown_key"),
|
|
761
|
+
("unknown_key_inside_a_union", "unknown_key"),
|
|
762
|
+
("a_union_mixing_two_measure_kinds", "unknown_key"),
|
|
763
|
+
("a_not_stated_period_is_whole", "conflicting_facts"),
|
|
764
|
+
("same_as_figure_as_a_figures_own_period", "statement_invalid"),
|
|
765
|
+
("row_group_not_ascending", "statements_invalid"),
|
|
766
|
+
("an_input_that_cannot_be_completed", "input_not_a_figure"),
|
|
767
|
+
("an_input_that_is_not_a_figure", "input_not_a_figure"),
|
|
768
|
+
("an_input_cycle", "input_cycle"),
|
|
769
|
+
("place_key_and_a_different_literal_field", "conflicting_facts"),
|
|
770
|
+
("place_key_and_an_equal_literal_field", "conflicting_facts"),
|
|
771
|
+
("place_key_in_an_inline_input", "statement_invalid"),
|
|
772
|
+
("a_member_group_not_in_code_point_order", "statements_invalid"),
|
|
773
|
+
("an_input_that_is_the_figure", "input_is_the_figure"),
|
|
774
|
+
("a_projected_input_under_an_actual_figure", "projected_input"),
|
|
775
|
+
("a_nested_input_that_is_the_figure", "input_is_the_figure"),
|
|
776
|
+
("a_nested_input_cycle", "input_cycle"),
|
|
777
|
+
("a_nested_input_that_is_not_a_figure", "input_not_a_figure"),
|
|
778
|
+
("a_nested_projected_input_under_an_actual_figure_through_same_as_figure", "projected_input"),
|
|
779
|
+
("a_nested_input_that_cannot_be_completed", "input_not_a_figure"),
|
|
780
|
+
],
|
|
781
|
+
)
|
|
782
|
+
def test_validate_statement_entries_refuses_malformed_and_incomplete_entries_without_result(
|
|
783
|
+
name: str, expected_code: str
|
|
784
|
+
) -> None:
|
|
785
|
+
with pytest.raises(StatementsRefused) as raised:
|
|
786
|
+
validate_statement_entries(copy.deepcopy(REFUSALS[name]["statements"]))
|
|
787
|
+
assert raised.value.code == expected_code
|
|
788
|
+
|
|
789
|
+
|
|
790
|
+
def test_validate_statement_entries_resolves_complement_and_cross_row_place_inputs_on_demand() -> None:
|
|
791
|
+
for case_name in (
|
|
792
|
+
"member_complement_with_computed_ratio_column",
|
|
793
|
+
"wildcard_rows_with_cross_row_growth_input",
|
|
794
|
+
):
|
|
795
|
+
entries = validate_statement_entries(copy.deepcopy(CASES[case_name]["statements"]))
|
|
796
|
+
assert statement_measure_kinds(entries) == frozenset({"vendor", "computed"})
|
|
797
|
+
|
|
798
|
+
# Excluded key in MemberComplement is NOT covered -> must still fail closed with input_not_a_figure.
|
|
799
|
+
excluded_input = copy.deepcopy(CASES["member_complement_with_computed_ratio_column"]["statements"])
|
|
800
|
+
excluded_input[0]["at"] = ["data", None, {"except": ["fcf_margin", "freeCashFlow"]}]
|
|
801
|
+
with pytest.raises(StatementsRefused) as exc_complement:
|
|
802
|
+
validate_statement_entries(excluded_input)
|
|
803
|
+
assert exc_complement.value.code == "input_not_a_figure"
|
|
804
|
+
|
|
805
|
+
# Row group [0] does not cover index 1 -> cross-row reference to index 1 must fail closed.
|
|
806
|
+
uncovered_row = copy.deepcopy(CASES["wildcard_rows_with_cross_row_growth_input"]["statements"])
|
|
807
|
+
uncovered_row[0]["at"] = ["data", [0], "revenue"]
|
|
808
|
+
with pytest.raises(StatementsRefused) as exc_row:
|
|
809
|
+
validate_statement_entries(uncovered_row)
|
|
810
|
+
assert exc_row.value.code == "input_not_a_figure"
|
|
811
|
+
|
|
812
|
+
# Cross-row cycle via wildcard None (data[0].a -> data[1].b -> data[0].a) is caught on demand.
|
|
813
|
+
period = copy.deepcopy(CASES["wildcard_rows_with_cross_row_growth_input"]["statements"][1]["period"])
|
|
814
|
+
basis = {"kind": "not_stated", "reason": "basis_not_recorded"}
|
|
815
|
+
cyclic_cross_row = [
|
|
816
|
+
{
|
|
817
|
+
"at": ["data", None, "a"],
|
|
818
|
+
"measure": {
|
|
819
|
+
"kind": "computed",
|
|
820
|
+
"operation": "sum",
|
|
821
|
+
"parameters": {},
|
|
822
|
+
"inputs": [{"kind": "place", "place": ["data", 1, "b"]}],
|
|
823
|
+
},
|
|
824
|
+
"period": period,
|
|
825
|
+
"basis": basis,
|
|
826
|
+
},
|
|
827
|
+
{
|
|
828
|
+
"at": ["data", None, "b"],
|
|
829
|
+
"measure": {
|
|
830
|
+
"kind": "computed",
|
|
831
|
+
"operation": "sum",
|
|
832
|
+
"parameters": {},
|
|
833
|
+
"inputs": [{"kind": "place", "place": ["data", 0, "a"]}],
|
|
834
|
+
},
|
|
835
|
+
"period": period,
|
|
836
|
+
"basis": basis,
|
|
837
|
+
},
|
|
838
|
+
]
|
|
839
|
+
with pytest.raises(StatementsRefused) as exc_cycle:
|
|
840
|
+
validate_statement_entries(cyclic_cross_row)
|
|
841
|
+
assert exc_cycle.value.code == "input_cycle"
|
|
842
|
+
|
|
843
|
+
|
|
844
|
+
_NS_VENDOR = {
|
|
845
|
+
"kind": "vendor",
|
|
846
|
+
"provider": "fmp",
|
|
847
|
+
"endpoint": "income_statement",
|
|
848
|
+
"definition": {"kind": "not_stated", "reason": "definition_not_recorded"},
|
|
849
|
+
"classification": {"kind": "not_stated", "reason": "classification_not_recorded"},
|
|
850
|
+
}
|
|
851
|
+
_NS_PERIOD = {"kind": "not_stated", "reason": "period_not_recorded"}
|
|
852
|
+
_NS_BASIS = {"kind": "not_stated", "reason": "basis_not_recorded"}
|
|
853
|
+
|
|
854
|
+
# Each table is one `resolve_statements` accepts for its real result. The check
|
|
855
|
+
# that has no result must not refuse a table the check that has one accepts.
|
|
856
|
+
_TABLES_RESOLVE_ACCEPTS = {
|
|
857
|
+
"a_ragged_row_beside_a_column_only_fuller_rows_have": (
|
|
858
|
+
[
|
|
859
|
+
{"at": ["data", None], "measure": _NS_VENDOR, "period": _NS_PERIOD, "basis": _NS_BASIS},
|
|
860
|
+
{"at": ["data", 0], "measure": {"field": "revenue"}},
|
|
861
|
+
{"at": ["data", None, "eps"], "measure": {"field": "eps"}},
|
|
862
|
+
{"at": ["data", 1, "revenue"], "measure": {"field": "revenue"}},
|
|
863
|
+
],
|
|
864
|
+
{"data": [{"revenue": 1.0, "eps": None}, {"revenue": 2.0, "eps": 3.0}]},
|
|
865
|
+
),
|
|
866
|
+
"a_place_key_entry_above_a_deeper_overlapping_entry": (
|
|
867
|
+
[
|
|
868
|
+
{"at": ["data"], "measure": {**_NS_VENDOR, "field": {"kind": "place_key"}}, "basis": _NS_BASIS},
|
|
869
|
+
{"at": ["data", None], "period": _NS_PERIOD},
|
|
870
|
+
],
|
|
871
|
+
{"data": [{"epsAvg": 1.0}]},
|
|
872
|
+
),
|
|
873
|
+
"a_computed_row_whose_input_row_is_completed_deeper": (
|
|
874
|
+
[
|
|
875
|
+
{"at": ["comparison", 0], "measure": {**_NS_VENDOR, "field": "x"}, "basis": _NS_BASIS},
|
|
876
|
+
{"at": ["comparison", 0, "AAPL"], "period": _NS_PERIOD},
|
|
877
|
+
{
|
|
878
|
+
"at": ["comparison", 1],
|
|
879
|
+
"measure": {
|
|
880
|
+
"kind": "computed",
|
|
881
|
+
"operation": "ratio",
|
|
882
|
+
"parameters": {},
|
|
883
|
+
"inputs": [{"kind": "place", "place": ["comparison", 0]}],
|
|
884
|
+
},
|
|
885
|
+
"period": _NS_PERIOD,
|
|
886
|
+
"basis": _NS_BASIS,
|
|
887
|
+
},
|
|
888
|
+
],
|
|
889
|
+
{"comparison": [{"AAPL": 1.0}, {"AAPL": 2.0}]},
|
|
890
|
+
),
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
@pytest.mark.parametrize("name", sorted(_TABLES_RESOLVE_ACCEPTS))
|
|
895
|
+
def test_a_table_resolve_accepts_is_not_refused_without_its_result(name: str) -> None:
|
|
896
|
+
statements, result = _TABLES_RESOLVE_ACCEPTS[name]
|
|
897
|
+
|
|
898
|
+
assert resolve_statements(copy.deepcopy(statements), result)
|
|
899
|
+
|
|
900
|
+
validate_statement_entries(copy.deepcopy(statements))
|
|
@@ -14,6 +14,10 @@ from .figure_statement import (
|
|
|
14
14
|
AbsentOperand,
|
|
15
15
|
AnswerPlaceReference,
|
|
16
16
|
AsOfPeriod,
|
|
17
|
+
BASIS_VALUES,
|
|
18
|
+
BROKERS,
|
|
19
|
+
Basis,
|
|
20
|
+
Broker,
|
|
17
21
|
BrokerReportedMeasure,
|
|
18
22
|
ComputedMeasure,
|
|
19
23
|
FigureStatement,
|
|
@@ -22,15 +26,22 @@ from .figure_statement import (
|
|
|
22
26
|
FiledLine,
|
|
23
27
|
FiscalPeriod,
|
|
24
28
|
IssuerFiledMeasure,
|
|
29
|
+
MEASURE_KINDS,
|
|
30
|
+
MeasureKind,
|
|
25
31
|
ModelVersion,
|
|
26
32
|
NOT_STATED_PHRASES,
|
|
33
|
+
NOT_STATED_REASONS,
|
|
27
34
|
NOT_STATED_SLOTS,
|
|
28
35
|
NotStated,
|
|
36
|
+
NotStatedReason,
|
|
37
|
+
PRODUCT_STATEMENT_MEASURE_KINDS,
|
|
29
38
|
PlaceKey,
|
|
30
39
|
ProductModelMeasure,
|
|
40
|
+
ProductStatementMeasureKind,
|
|
31
41
|
RecordedDefinition,
|
|
32
42
|
RowPlaceReference,
|
|
33
43
|
SameAsFigure,
|
|
44
|
+
SkillArtifactMeasure,
|
|
34
45
|
StatementEntry,
|
|
35
46
|
StatementsRefused,
|
|
36
47
|
TemplateRow,
|
|
@@ -42,6 +53,7 @@ from .figure_statement import (
|
|
|
42
53
|
expand_same_as_figure,
|
|
43
54
|
figure_places,
|
|
44
55
|
figure_statement_vocabulary,
|
|
56
|
+
is_product_statement_measure_kind,
|
|
45
57
|
not_stated,
|
|
46
58
|
parse_figure_statement,
|
|
47
59
|
parse_statements,
|
|
@@ -50,7 +62,9 @@ from .figure_statement import (
|
|
|
50
62
|
render_statement_label,
|
|
51
63
|
render_statements,
|
|
52
64
|
resolve_statements,
|
|
65
|
+
statement_measure_kinds,
|
|
53
66
|
trailing_alignment,
|
|
67
|
+
validate_statement_entries,
|
|
54
68
|
)
|
|
55
69
|
from .formatting import format_numeric, normalize_declared_numeric, numeric_unit_tag
|
|
56
70
|
from .forward_ev_adjusted_ebitda import (
|
|
@@ -201,6 +215,10 @@ __all__ = [
|
|
|
201
215
|
"AbsentOperand",
|
|
202
216
|
"AnswerPlaceReference",
|
|
203
217
|
"AsOfPeriod",
|
|
218
|
+
"BASIS_VALUES",
|
|
219
|
+
"BROKERS",
|
|
220
|
+
"Basis",
|
|
221
|
+
"Broker",
|
|
204
222
|
"BrokerReportedMeasure",
|
|
205
223
|
"ComputedMeasure",
|
|
206
224
|
"FigureStatement",
|
|
@@ -209,15 +227,22 @@ __all__ = [
|
|
|
209
227
|
"FiledLine",
|
|
210
228
|
"FiscalPeriod",
|
|
211
229
|
"IssuerFiledMeasure",
|
|
230
|
+
"MEASURE_KINDS",
|
|
231
|
+
"MeasureKind",
|
|
212
232
|
"ModelVersion",
|
|
213
233
|
"NOT_STATED_PHRASES",
|
|
234
|
+
"NOT_STATED_REASONS",
|
|
214
235
|
"NOT_STATED_SLOTS",
|
|
215
236
|
"NotStated",
|
|
237
|
+
"NotStatedReason",
|
|
238
|
+
"PRODUCT_STATEMENT_MEASURE_KINDS",
|
|
216
239
|
"PlaceKey",
|
|
217
240
|
"ProductModelMeasure",
|
|
241
|
+
"ProductStatementMeasureKind",
|
|
218
242
|
"RecordedDefinition",
|
|
219
243
|
"RowPlaceReference",
|
|
220
244
|
"SameAsFigure",
|
|
245
|
+
"SkillArtifactMeasure",
|
|
221
246
|
"StatementEntry",
|
|
222
247
|
"StatementsRefused",
|
|
223
248
|
"TemplateRow",
|
|
@@ -229,6 +254,7 @@ __all__ = [
|
|
|
229
254
|
"expand_same_as_figure",
|
|
230
255
|
"figure_places",
|
|
231
256
|
"figure_statement_vocabulary",
|
|
257
|
+
"is_product_statement_measure_kind",
|
|
232
258
|
"not_stated",
|
|
233
259
|
"parse_figure_statement",
|
|
234
260
|
"parse_statements",
|
|
@@ -237,5 +263,7 @@ __all__ = [
|
|
|
237
263
|
"render_statement_label",
|
|
238
264
|
"render_statements",
|
|
239
265
|
"resolve_statements",
|
|
266
|
+
"statement_measure_kinds",
|
|
240
267
|
"trailing_alignment",
|
|
268
|
+
"validate_statement_entries",
|
|
241
269
|
]
|
{value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core/figure_statement.py
RENAMED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
"""What a figure measures, stated as typed data by the code that owns its world.
|
|
2
2
|
|
|
3
|
-
Ruling ``EVERY-FIGURE-STATES-ITS-WORLD-2026-11-18
|
|
4
|
-
carries
|
|
5
|
-
(``measure``),
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
and
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
``not_stated`` object with a closed reason, never an omitted key, a null or
|
|
3
|
+
Ruling ``EVERY-FIGURE-STATES-ITS-WORLD-2026-11-18``: every figure's statement
|
|
4
|
+
carries the active five-fact contract across the statement and its carrier row:
|
|
5
|
+
whose measure a figure is and its definition (``measure``), how its period was
|
|
6
|
+
built and whether it is ``actual`` or ``projected`` (``period``), and the
|
|
7
|
+
accounting ``basis`` of the measure's definition (``basis``). ``unit`` and
|
|
8
|
+
``source`` are carried on the ``Source`` row itself (its value-semantics fields
|
|
9
|
+
and row identity), never duplicated inside the statement JSON.
|
|
10
|
+
|
|
11
|
+
Inside ``measure``, ``period`` and ``basis`` a fact that cannot be filled is
|
|
12
|
+
the ``not_stated`` object with a closed reason, never an omitted key, a null or
|
|
14
13
|
a guess. A reason is admitted only in the slots ``NOT_STATED_SLOTS`` names.
|
|
15
14
|
|
|
16
15
|
Every member is a reference to an identity that already exists: the filed
|
|
@@ -33,10 +32,12 @@ declared figure or refuses them.
|
|
|
33
32
|
|
|
34
33
|
from __future__ import annotations
|
|
35
34
|
|
|
36
|
-
from collections
|
|
35
|
+
from collections import deque
|
|
36
|
+
from collections.abc import Callable, Mapping, Sequence
|
|
37
37
|
from dataclasses import dataclass
|
|
38
38
|
from datetime import date as calendar_date
|
|
39
39
|
from datetime import datetime
|
|
40
|
+
import itertools
|
|
40
41
|
import json
|
|
41
42
|
import math
|
|
42
43
|
from typing import Annotated, Any, Final, Literal, TypeAlias, get_args
|
|
@@ -188,9 +189,23 @@ RECORDED_DEFINITION_PHRASES: Final[dict[str, str]] = {
|
|
|
188
189
|
}
|
|
189
190
|
|
|
190
191
|
MeasureKind: TypeAlias = Literal[
|
|
191
|
-
"issuer_filed",
|
|
192
|
+
"issuer_filed",
|
|
193
|
+
"product_model",
|
|
194
|
+
"skill_artifact",
|
|
195
|
+
"vendor",
|
|
196
|
+
"broker_reported",
|
|
197
|
+
"computed",
|
|
192
198
|
]
|
|
193
199
|
MEASURE_KINDS: Final[tuple[str, ...]] = get_args(MeasureKind)
|
|
200
|
+
#: Measures authored by the product itself (never primary input evidence).
|
|
201
|
+
ProductStatementMeasureKind: TypeAlias = Literal[
|
|
202
|
+
"product_model",
|
|
203
|
+
"skill_artifact",
|
|
204
|
+
"computed",
|
|
205
|
+
]
|
|
206
|
+
PRODUCT_STATEMENT_MEASURE_KINDS: Final[frozenset[str]] = frozenset(
|
|
207
|
+
get_args(ProductStatementMeasureKind)
|
|
208
|
+
)
|
|
194
209
|
PeriodKind: TypeAlias = Literal["fiscal_period", "trailing", "as_of"]
|
|
195
210
|
PERIOD_KINDS: Final[tuple[str, ...]] = get_args(PeriodKind)
|
|
196
211
|
|
|
@@ -750,6 +765,28 @@ class ProductModelMeasure(_Strict):
|
|
|
750
765
|
model_item_id: Text
|
|
751
766
|
|
|
752
767
|
|
|
768
|
+
class SkillArtifactMeasure(_Strict):
|
|
769
|
+
"""A figure read from a stage's skill artifact: skill, artifact id and content hash.
|
|
770
|
+
|
|
771
|
+
Matches the three-field artifact reference of ``agent_workflow_contracts``
|
|
772
|
+
(``skill``, ``artifact_id``, ``content_sha256``), with optional ``field``
|
|
773
|
+
when a specific verdict or typed-output path is named.
|
|
774
|
+
"""
|
|
775
|
+
|
|
776
|
+
kind: Literal["skill_artifact"]
|
|
777
|
+
skill: Text
|
|
778
|
+
artifact_id: Text
|
|
779
|
+
content_sha256: Sha256Hex
|
|
780
|
+
field: Annotated[Text | None, Field(exclude_if=_absent)] = None
|
|
781
|
+
|
|
782
|
+
@model_validator(mode="before")
|
|
783
|
+
@classmethod
|
|
784
|
+
def _no_null_field(cls, data: Any) -> Any:
|
|
785
|
+
if isinstance(data, dict) and "field" in data and data["field"] is None:
|
|
786
|
+
raise ValueError("field is non-blank text; omit the key instead of null")
|
|
787
|
+
return data
|
|
788
|
+
|
|
789
|
+
|
|
753
790
|
class RecordedDefinition(_Strict):
|
|
754
791
|
"""The provider's own definition, by its capture artifact and what it records.
|
|
755
792
|
|
|
@@ -976,6 +1013,7 @@ class ComputedMeasure(_Strict):
|
|
|
976
1013
|
Measure: TypeAlias = Annotated[
|
|
977
1014
|
IssuerFiledMeasure
|
|
978
1015
|
| ProductModelMeasure
|
|
1016
|
+
| SkillArtifactMeasure
|
|
979
1017
|
| VendorMeasure
|
|
980
1018
|
| BrokerReportedMeasure
|
|
981
1019
|
| ComputedMeasure,
|
|
@@ -1033,25 +1071,19 @@ def _refuse_projected_inline_inputs(
|
|
|
1033
1071
|
|
|
1034
1072
|
|
|
1035
1073
|
class FigureStatement(_Strict):
|
|
1036
|
-
"""What one figure measures: ``measure
|
|
1074
|
+
"""What one figure measures: ``measure``, ``period``, and ``basis``.
|
|
1037
1075
|
|
|
1038
1076
|
``period`` may itself be not stated (``period_not_recorded``) for a row
|
|
1039
|
-
whose period rule is not recorded;
|
|
1040
|
-
``
|
|
1041
|
-
``
|
|
1042
|
-
|
|
1077
|
+
whose period rule is not recorded; ``basis`` may be not stated
|
|
1078
|
+
(``basis_not_recorded`` or, for a vendor figure,
|
|
1079
|
+
``vendor_figure_not_compared_to_filing``). ``same_as_figure`` is admitted
|
|
1080
|
+
only as an inline input's period. ``unit`` and ``source`` belong to the
|
|
1081
|
+
source row carrying this statement.
|
|
1043
1082
|
"""
|
|
1044
1083
|
|
|
1045
1084
|
measure: Measure
|
|
1046
1085
|
period: StatedPeriod
|
|
1047
|
-
basis:
|
|
1048
|
-
|
|
1049
|
-
@model_validator(mode="before")
|
|
1050
|
-
@classmethod
|
|
1051
|
-
def _no_null_basis(cls, data: Any) -> Any:
|
|
1052
|
-
if isinstance(data, dict) and "basis" in data and data["basis"] is None:
|
|
1053
|
-
raise ValueError("basis is a closed value or not stated; omit the key instead of null")
|
|
1054
|
-
return data
|
|
1086
|
+
basis: Basis | NotStated
|
|
1055
1087
|
|
|
1056
1088
|
@model_validator(mode="after")
|
|
1057
1089
|
def _consistent(self) -> FigureStatement:
|
|
@@ -1392,7 +1424,9 @@ def _align(pattern: Pattern, place: Place) -> Place | None:
|
|
|
1392
1424
|
def _resolve_inputs(
|
|
1393
1425
|
statement: FigureStatement,
|
|
1394
1426
|
place: Place,
|
|
1395
|
-
resolved:
|
|
1427
|
+
resolved: Mapping[Place, FigureStatement],
|
|
1428
|
+
*,
|
|
1429
|
+
on_missing_place: Callable[[Place], FigureStatement | None] | None = None,
|
|
1396
1430
|
) -> tuple[FigureStatement, list[Place]]:
|
|
1397
1431
|
"""The figure's statement with every in-answer input resolved, and their targets.
|
|
1398
1432
|
|
|
@@ -1445,6 +1479,8 @@ def _resolve_inputs(
|
|
|
1445
1479
|
"input_is_the_figure", "a figure is not its own input", place=place
|
|
1446
1480
|
)
|
|
1447
1481
|
input_statement = resolved.get(target)
|
|
1482
|
+
if input_statement is None and on_missing_place is not None:
|
|
1483
|
+
input_statement = on_missing_place(target)
|
|
1448
1484
|
if input_statement is None:
|
|
1449
1485
|
raise StatementsRefused(
|
|
1450
1486
|
"input_not_a_figure",
|
|
@@ -1569,7 +1605,7 @@ def resolve_statements(
|
|
|
1569
1605
|
for index, entry in enumerate(entries):
|
|
1570
1606
|
if _covers(entry.pattern, place):
|
|
1571
1607
|
_merge(union, entry.facts(), entry=index, path=(), owners=owners, conflict=conflict)
|
|
1572
|
-
for fact in
|
|
1608
|
+
for fact in _FACTS:
|
|
1573
1609
|
if fact not in union:
|
|
1574
1610
|
raise StatementsRefused(
|
|
1575
1611
|
"figure_not_stated",
|
|
@@ -1616,6 +1652,351 @@ def resolve_statements(
|
|
|
1616
1652
|
return final
|
|
1617
1653
|
|
|
1618
1654
|
|
|
1655
|
+
def _is_int_pattern_segment(segment: PatternSegment) -> bool:
|
|
1656
|
+
return (
|
|
1657
|
+
segment is None
|
|
1658
|
+
or isinstance(segment, int)
|
|
1659
|
+
or (isinstance(segment, tuple) and isinstance(segment[0], int))
|
|
1660
|
+
)
|
|
1661
|
+
|
|
1662
|
+
|
|
1663
|
+
def _int_segment_set(segment: PatternSegment) -> set[int] | Literal["any"] | None:
|
|
1664
|
+
if segment is None:
|
|
1665
|
+
return "any"
|
|
1666
|
+
if isinstance(segment, int):
|
|
1667
|
+
return {segment}
|
|
1668
|
+
if isinstance(segment, tuple) and isinstance(segment[0], int):
|
|
1669
|
+
return {item for item in segment if isinstance(item, int)}
|
|
1670
|
+
return None
|
|
1671
|
+
|
|
1672
|
+
|
|
1673
|
+
def _str_segment_names(segment: PatternSegment) -> set[str] | MemberComplement | None:
|
|
1674
|
+
if isinstance(segment, str):
|
|
1675
|
+
return {segment}
|
|
1676
|
+
if isinstance(segment, MemberComplement):
|
|
1677
|
+
return segment
|
|
1678
|
+
if isinstance(segment, tuple) and isinstance(segment[0], str):
|
|
1679
|
+
return {item for item in segment if isinstance(item, str)}
|
|
1680
|
+
return None
|
|
1681
|
+
|
|
1682
|
+
|
|
1683
|
+
def _segments_overlap(first: PatternSegment, second: PatternSegment) -> bool:
|
|
1684
|
+
first_ints = _int_segment_set(first)
|
|
1685
|
+
second_ints = _int_segment_set(second)
|
|
1686
|
+
if first_ints is not None or second_ints is not None:
|
|
1687
|
+
if first_ints is None or second_ints is None:
|
|
1688
|
+
return False
|
|
1689
|
+
if first_ints == "any" or second_ints == "any":
|
|
1690
|
+
return True
|
|
1691
|
+
return bool(first_ints & second_ints)
|
|
1692
|
+
first_strs = _str_segment_names(first)
|
|
1693
|
+
second_strs = _str_segment_names(second)
|
|
1694
|
+
if first_strs is None or second_strs is None:
|
|
1695
|
+
return False
|
|
1696
|
+
if isinstance(first_strs, MemberComplement):
|
|
1697
|
+
if isinstance(second_strs, MemberComplement):
|
|
1698
|
+
return True
|
|
1699
|
+
return any(name not in first_strs.names for name in second_strs)
|
|
1700
|
+
if isinstance(second_strs, MemberComplement):
|
|
1701
|
+
return any(name not in second_strs.names for name in first_strs)
|
|
1702
|
+
return bool(first_strs & second_strs)
|
|
1703
|
+
|
|
1704
|
+
|
|
1705
|
+
def _patterns_overlap(first: Pattern, second: Pattern) -> bool:
|
|
1706
|
+
return all(_segments_overlap(a, b) for a, b in zip(first, second))
|
|
1707
|
+
|
|
1708
|
+
|
|
1709
|
+
def _fresh_member_name(excluded: set[str]) -> str:
|
|
1710
|
+
candidate = "__field__"
|
|
1711
|
+
counter = 0
|
|
1712
|
+
while candidate in excluded:
|
|
1713
|
+
counter += 1
|
|
1714
|
+
candidate = f"__field_{counter}__"
|
|
1715
|
+
return candidate
|
|
1716
|
+
|
|
1717
|
+
|
|
1718
|
+
def _witness_places_for_entry(
|
|
1719
|
+
target: StatementEntry,
|
|
1720
|
+
entries: Sequence[StatementEntry],
|
|
1721
|
+
) -> list[Place]:
|
|
1722
|
+
overlapping = [
|
|
1723
|
+
entry for entry in entries if _patterns_overlap(target.pattern, entry.pattern)
|
|
1724
|
+
]
|
|
1725
|
+
max_depth = max(len(entry.pattern) for entry in overlapping)
|
|
1726
|
+
# A `place_key` names the field by the string at the figure's last segment.
|
|
1727
|
+
# When the deepest covering pattern ends in an index, the figure it covers
|
|
1728
|
+
# lies one member below, whichever entry carries the `place_key`.
|
|
1729
|
+
has_place_key = any(
|
|
1730
|
+
isinstance(entry.measure, dict) and entry.measure.get("field") == {"kind": "place_key"}
|
|
1731
|
+
for entry in overlapping
|
|
1732
|
+
)
|
|
1733
|
+
deepest_ends_in_index = max_depth == 0 or any(
|
|
1734
|
+
len(entry.pattern) == max_depth and _is_int_pattern_segment(entry.pattern[-1])
|
|
1735
|
+
for entry in overlapping
|
|
1736
|
+
)
|
|
1737
|
+
depth = max_depth + (1 if has_place_key and deepest_ends_in_index else 0)
|
|
1738
|
+
if depth == 0:
|
|
1739
|
+
return [()]
|
|
1740
|
+
steps_by_pos: list[list[str | int]] = []
|
|
1741
|
+
for pos in range(depth):
|
|
1742
|
+
segs = [entry.pattern[pos] for entry in overlapping if pos < len(entry.pattern)]
|
|
1743
|
+
if not segs:
|
|
1744
|
+
steps_by_pos.append(["__field__"])
|
|
1745
|
+
continue
|
|
1746
|
+
int_steps: list[int] = []
|
|
1747
|
+
str_steps: list[str] = []
|
|
1748
|
+
excluded_names: set[str] = set()
|
|
1749
|
+
has_wildcard_int = False
|
|
1750
|
+
has_complement = False
|
|
1751
|
+
for seg in segs:
|
|
1752
|
+
if seg is None:
|
|
1753
|
+
has_wildcard_int = True
|
|
1754
|
+
elif isinstance(seg, int):
|
|
1755
|
+
if seg not in int_steps:
|
|
1756
|
+
int_steps.append(seg)
|
|
1757
|
+
elif isinstance(seg, str):
|
|
1758
|
+
if seg not in str_steps:
|
|
1759
|
+
str_steps.append(seg)
|
|
1760
|
+
elif isinstance(seg, MemberComplement):
|
|
1761
|
+
has_complement = True
|
|
1762
|
+
excluded_names.update(seg.names)
|
|
1763
|
+
elif isinstance(seg, tuple) and isinstance(seg[0], int):
|
|
1764
|
+
for item in seg:
|
|
1765
|
+
if isinstance(item, int) and item not in int_steps:
|
|
1766
|
+
int_steps.append(item)
|
|
1767
|
+
elif isinstance(seg, tuple) and isinstance(seg[0], str):
|
|
1768
|
+
for item in seg:
|
|
1769
|
+
if isinstance(item, str) and item not in str_steps:
|
|
1770
|
+
str_steps.append(item)
|
|
1771
|
+
named_index = bool(int_steps)
|
|
1772
|
+
if has_wildcard_int and not int_steps:
|
|
1773
|
+
int_steps.append(0)
|
|
1774
|
+
# Where the target admits more than the other entries name (a wildcard
|
|
1775
|
+
# index, a member complement, or any step below its own pattern), it
|
|
1776
|
+
# also covers a row or member no other entry speaks of: one such step
|
|
1777
|
+
# stands for them, so the target is tried apart from its neighbours.
|
|
1778
|
+
beyond = pos >= len(target.pattern)
|
|
1779
|
+
target_segment = None if beyond else target.pattern[pos]
|
|
1780
|
+
open_index = named_index and (beyond or target_segment is None)
|
|
1781
|
+
open_member = has_complement or (beyond and bool(str_steps))
|
|
1782
|
+
if open_index:
|
|
1783
|
+
int_steps.append(max(int_steps) + 1)
|
|
1784
|
+
if open_member:
|
|
1785
|
+
fresh = _fresh_member_name(excluded_names | set(str_steps))
|
|
1786
|
+
str_steps.append(fresh)
|
|
1787
|
+
raw_steps: list[str | int] = [*int_steps, *str_steps]
|
|
1788
|
+
if not beyond:
|
|
1789
|
+
raw_steps = [
|
|
1790
|
+
step for step in raw_steps if _segment_covers(target.pattern[pos], step)
|
|
1791
|
+
]
|
|
1792
|
+
steps_by_pos.append(raw_steps)
|
|
1793
|
+
return [tuple(combo) for combo in itertools.product(*steps_by_pos)]
|
|
1794
|
+
|
|
1795
|
+
|
|
1796
|
+
def _try_resolve_entry_place(
|
|
1797
|
+
place: Place,
|
|
1798
|
+
entries: Sequence[StatementEntry],
|
|
1799
|
+
) -> tuple[FigureStatement | None, list[str]]:
|
|
1800
|
+
union: dict[str, Any] = {}
|
|
1801
|
+
owners: dict[tuple[str, ...], int] = {}
|
|
1802
|
+
|
|
1803
|
+
def conflict(first: int, second: int, key: str, place: Place = place) -> None:
|
|
1804
|
+
raise StatementsRefused(
|
|
1805
|
+
"conflicting_facts",
|
|
1806
|
+
"two covering entries state one key differently",
|
|
1807
|
+
place=place,
|
|
1808
|
+
entries=(first, second),
|
|
1809
|
+
ats=(entries[first].at, entries[second].at),
|
|
1810
|
+
fact=key,
|
|
1811
|
+
)
|
|
1812
|
+
|
|
1813
|
+
for index, entry in enumerate(entries):
|
|
1814
|
+
if _covers(entry.pattern, place):
|
|
1815
|
+
_merge(
|
|
1816
|
+
union,
|
|
1817
|
+
entry.facts(),
|
|
1818
|
+
entry=index,
|
|
1819
|
+
path=(),
|
|
1820
|
+
owners=owners,
|
|
1821
|
+
conflict=conflict,
|
|
1822
|
+
)
|
|
1823
|
+
missing = [fact for fact in _FACTS if fact not in union]
|
|
1824
|
+
if missing:
|
|
1825
|
+
return None, missing
|
|
1826
|
+
try:
|
|
1827
|
+
statement = FigureStatement.model_validate(union)
|
|
1828
|
+
except ValidationError as exc:
|
|
1829
|
+
first = exc.errors(include_url=False)[0]
|
|
1830
|
+
code: StatementsRefusalCode = (
|
|
1831
|
+
"unknown_key" if first["type"] == "extra_forbidden" else "statement_invalid"
|
|
1832
|
+
)
|
|
1833
|
+
raise StatementsRefused(
|
|
1834
|
+
code,
|
|
1835
|
+
str(first["msg"]),
|
|
1836
|
+
place=place,
|
|
1837
|
+
fact=".".join(str(part) for part in first["loc"]),
|
|
1838
|
+
) from exc
|
|
1839
|
+
if isinstance(statement.period, SameAsFigure):
|
|
1840
|
+
raise StatementsRefused(
|
|
1841
|
+
"statement_invalid",
|
|
1842
|
+
"a figure's own period is not same_as_figure",
|
|
1843
|
+
place=place,
|
|
1844
|
+
fact="period",
|
|
1845
|
+
)
|
|
1846
|
+
measure = statement.measure
|
|
1847
|
+
if (
|
|
1848
|
+
isinstance(measure, VendorMeasure)
|
|
1849
|
+
and isinstance(measure.field, PlaceKey)
|
|
1850
|
+
and (not place or not isinstance(place[-1], str))
|
|
1851
|
+
):
|
|
1852
|
+
raise StatementsRefused(
|
|
1853
|
+
"place_key_not_a_key",
|
|
1854
|
+
"place_key names the vendor's field by the string at the figure's last "
|
|
1855
|
+
"segment; this figure's last segment is a list index",
|
|
1856
|
+
place=place,
|
|
1857
|
+
fact="measure.field",
|
|
1858
|
+
)
|
|
1859
|
+
return statement, []
|
|
1860
|
+
|
|
1861
|
+
|
|
1862
|
+
def _steps_below(place: Place, entries: Sequence[StatementEntry]) -> list[str | int]:
|
|
1863
|
+
"""One concrete step under ``place`` for each segment an entry's pattern holds there."""
|
|
1864
|
+
|
|
1865
|
+
steps: list[str | int] = []
|
|
1866
|
+
depth = len(place)
|
|
1867
|
+
for entry in entries:
|
|
1868
|
+
pattern = entry.pattern
|
|
1869
|
+
if len(pattern) <= depth or not _covers(pattern[:depth], place):
|
|
1870
|
+
continue
|
|
1871
|
+
segment = pattern[depth]
|
|
1872
|
+
if segment is None:
|
|
1873
|
+
found: list[str | int] = [0]
|
|
1874
|
+
elif isinstance(segment, (int, str)):
|
|
1875
|
+
found = [segment]
|
|
1876
|
+
elif isinstance(segment, MemberComplement):
|
|
1877
|
+
found = [_fresh_member_name(set(segment.names))]
|
|
1878
|
+
else:
|
|
1879
|
+
found = list(segment)
|
|
1880
|
+
steps.extend(step for step in found if step not in steps)
|
|
1881
|
+
return steps
|
|
1882
|
+
|
|
1883
|
+
|
|
1884
|
+
def _resolve_witness_statements(
|
|
1885
|
+
entries: Sequence[StatementEntry],
|
|
1886
|
+
) -> dict[Place, FigureStatement]:
|
|
1887
|
+
resolved: dict[Place, FigureStatement] = {}
|
|
1888
|
+
for target_index, target in enumerate(entries):
|
|
1889
|
+
witnesses = _witness_places_for_entry(target, entries)
|
|
1890
|
+
complete_count = 0
|
|
1891
|
+
best_missing_place: Place = witnesses[0] if witnesses else ()
|
|
1892
|
+
best_missing_fact: str = "measure"
|
|
1893
|
+
best_present_count = -1
|
|
1894
|
+
# A witness is a place the patterns could cover, not a figure of any
|
|
1895
|
+
# result: two patterns may meet at a place that holds no number. So a
|
|
1896
|
+
# refusal at one witness refuses the entry only when no witness of the
|
|
1897
|
+
# entry completes; with the result in hand, `resolve_statements` owns
|
|
1898
|
+
# the refusal at a real figure.
|
|
1899
|
+
first_refusal: StatementsRefused | None = None
|
|
1900
|
+
for place in witnesses:
|
|
1901
|
+
if place in resolved:
|
|
1902
|
+
complete_count += 1
|
|
1903
|
+
continue
|
|
1904
|
+
try:
|
|
1905
|
+
statement, missing = _try_resolve_entry_place(place, entries)
|
|
1906
|
+
except StatementsRefused as refusal:
|
|
1907
|
+
if first_refusal is None:
|
|
1908
|
+
first_refusal = refusal
|
|
1909
|
+
continue
|
|
1910
|
+
if statement is None:
|
|
1911
|
+
present_count = len(_FACTS) - len(missing)
|
|
1912
|
+
if present_count > best_present_count:
|
|
1913
|
+
best_present_count = present_count
|
|
1914
|
+
best_missing_place = place
|
|
1915
|
+
best_missing_fact = missing[0]
|
|
1916
|
+
continue
|
|
1917
|
+
resolved[place] = statement
|
|
1918
|
+
complete_count += 1
|
|
1919
|
+
if complete_count == 0:
|
|
1920
|
+
if first_refusal is not None:
|
|
1921
|
+
raise first_refusal
|
|
1922
|
+
raise StatementsRefused(
|
|
1923
|
+
"figure_not_stated",
|
|
1924
|
+
"no entry covering the figure states this fact",
|
|
1925
|
+
place=best_missing_place,
|
|
1926
|
+
entries=(target_index,),
|
|
1927
|
+
ats=(target.at,),
|
|
1928
|
+
fact=best_missing_fact,
|
|
1929
|
+
)
|
|
1930
|
+
queue: deque[Place] = deque(resolved.keys())
|
|
1931
|
+
walked: set[Place] = set()
|
|
1932
|
+
edges: dict[Place, list[Place]] = {}
|
|
1933
|
+
|
|
1934
|
+
def resolve_on_demand(target_place: Place) -> FigureStatement | None:
|
|
1935
|
+
# An input may name a row whose figures lie deeper (a row of members):
|
|
1936
|
+
# with the result, the place is completed with the figure's trailing
|
|
1937
|
+
# segments. Without it, the row stands for any member an entry names
|
|
1938
|
+
# below it, so the input is a figure when one of those completes.
|
|
1939
|
+
candidates: deque[Place] = deque([target_place])
|
|
1940
|
+
tried: set[Place] = set()
|
|
1941
|
+
while candidates:
|
|
1942
|
+
candidate = candidates.popleft()
|
|
1943
|
+
if candidate in tried:
|
|
1944
|
+
continue
|
|
1945
|
+
tried.add(candidate)
|
|
1946
|
+
try:
|
|
1947
|
+
statement, _missing = _try_resolve_entry_place(candidate, entries)
|
|
1948
|
+
except StatementsRefused:
|
|
1949
|
+
statement = None
|
|
1950
|
+
if statement is not None:
|
|
1951
|
+
resolved[target_place] = statement
|
|
1952
|
+
queue.append(target_place)
|
|
1953
|
+
return statement
|
|
1954
|
+
for step in _steps_below(candidate, entries):
|
|
1955
|
+
candidates.append((*candidate, step))
|
|
1956
|
+
return None
|
|
1957
|
+
|
|
1958
|
+
while queue:
|
|
1959
|
+
place = queue.popleft()
|
|
1960
|
+
if place in walked:
|
|
1961
|
+
continue
|
|
1962
|
+
walked.add(place)
|
|
1963
|
+
_resolved_stmt, edges[place] = _resolve_inputs(
|
|
1964
|
+
resolved[place],
|
|
1965
|
+
place,
|
|
1966
|
+
resolved,
|
|
1967
|
+
on_missing_place=resolve_on_demand,
|
|
1968
|
+
)
|
|
1969
|
+
_refuse_input_cycles(edges)
|
|
1970
|
+
return resolved
|
|
1971
|
+
|
|
1972
|
+
|
|
1973
|
+
def validate_statement_entries(value: object) -> tuple[StatementEntry, ...]:
|
|
1974
|
+
"""Parse and validate a row's ``statements`` entries without requiring the raw result.
|
|
1975
|
+
|
|
1976
|
+
Every entry must pass ``parse_statements``, conflict with no overlapping
|
|
1977
|
+
entry, and participate in at least one complete, valid ``FigureStatement``
|
|
1978
|
+
(checking ``measure``, ``period``, ``basis``, ``place_key``, inline inputs,
|
|
1979
|
+
and in-answer ``place`` references across witness places).
|
|
1980
|
+
"""
|
|
1981
|
+
|
|
1982
|
+
entries = parse_statements(value)
|
|
1983
|
+
_resolve_witness_statements(entries)
|
|
1984
|
+
return tuple(entries)
|
|
1985
|
+
|
|
1986
|
+
|
|
1987
|
+
def statement_measure_kinds(entries: Sequence[StatementEntry]) -> frozenset[MeasureKind]:
|
|
1988
|
+
"""The typed ``MeasureKind`` set across a validated row's ``StatementEntry`` sequence."""
|
|
1989
|
+
|
|
1990
|
+
resolved = _resolve_witness_statements(entries)
|
|
1991
|
+
return frozenset(statement.measure.kind for statement in resolved.values())
|
|
1992
|
+
|
|
1993
|
+
|
|
1994
|
+
def is_product_statement_measure_kind(kind: object) -> bool:
|
|
1995
|
+
"""True when ``kind`` is a product-authored non-evidence measure kind."""
|
|
1996
|
+
|
|
1997
|
+
return isinstance(kind, str) and kind in PRODUCT_STATEMENT_MEASURE_KINDS
|
|
1998
|
+
|
|
1999
|
+
|
|
1619
2000
|
def _refuse_input_cycles(edges: dict[Place, list[Place]]) -> None:
|
|
1620
2001
|
"""Refuse a figure computed, through its in-answer inputs at any depth, from itself.
|
|
1621
2002
|
|
|
@@ -1720,6 +2101,13 @@ def _measure_label(measure: Mapping[str, Any]) -> str:
|
|
|
1720
2101
|
parts.append("the model")
|
|
1721
2102
|
if measure.get("model_item_id"):
|
|
1722
2103
|
parts.append(f"item {measure.get('model_item_id')}")
|
|
2104
|
+
elif kind == "skill_artifact":
|
|
2105
|
+
if measure.get("skill") and measure.get("artifact_id"):
|
|
2106
|
+
parts.append(f"{measure.get('skill')} artifact {measure.get('artifact_id')}")
|
|
2107
|
+
else:
|
|
2108
|
+
parts.append("skill artifact")
|
|
2109
|
+
if measure.get("field"):
|
|
2110
|
+
parts.append(f"field {measure.get('field')}")
|
|
1723
2111
|
elif kind == "broker_reported":
|
|
1724
2112
|
parts.append(f"{measure.get('broker')}'s {measure.get('field') or 'record'}")
|
|
1725
2113
|
if measure.get("account"):
|
|
@@ -1888,6 +2276,7 @@ def figure_statement_vocabulary() -> dict[str, Any]:
|
|
|
1888
2276
|
|
|
1889
2277
|
return {
|
|
1890
2278
|
"measure_kinds": list(MEASURE_KINDS),
|
|
2279
|
+
"product_statement_measure_kinds": list(get_args(ProductStatementMeasureKind)),
|
|
1891
2280
|
"period_kinds": list(PERIOD_KINDS),
|
|
1892
2281
|
"period_statuses": list(PERIOD_STATUSES),
|
|
1893
2282
|
"period_built": list(PERIOD_BUILT_VALUES),
|
|
@@ -1935,6 +2324,7 @@ __all__ = [
|
|
|
1935
2324
|
"InlineStatement",
|
|
1936
2325
|
"IssuerFiledMeasure",
|
|
1937
2326
|
"MEASURE_KINDS",
|
|
2327
|
+
"MeasureKind",
|
|
1938
2328
|
"MemberComplement",
|
|
1939
2329
|
"ModelVersion",
|
|
1940
2330
|
"NOT_STATED_PHRASES",
|
|
@@ -1946,17 +2336,20 @@ __all__ = [
|
|
|
1946
2336
|
"PERIOD_KINDS",
|
|
1947
2337
|
"PERIOD_STATUSES",
|
|
1948
2338
|
"PLACE_KEY_PHRASE",
|
|
2339
|
+
"PRODUCT_STATEMENT_MEASURE_KINDS",
|
|
1949
2340
|
"Pattern",
|
|
1950
2341
|
"PlaceKey",
|
|
1951
2342
|
"PeriodBuilt",
|
|
1952
2343
|
"PeriodStatus",
|
|
1953
2344
|
"Place",
|
|
1954
2345
|
"ProductModelMeasure",
|
|
2346
|
+
"ProductStatementMeasureKind",
|
|
1955
2347
|
"RECORDED_DEFINITION_PHRASES",
|
|
1956
2348
|
"RECORDED_DEFINITION_SEMANTICS",
|
|
1957
2349
|
"RecordedDefinition",
|
|
1958
2350
|
"RowPlaceReference",
|
|
1959
2351
|
"SameAsFigure",
|
|
2352
|
+
"SkillArtifactMeasure",
|
|
1960
2353
|
"StatedPeriod",
|
|
1961
2354
|
"STATEMENTS_REFUSAL_CODES",
|
|
1962
2355
|
"StatementEntry",
|
|
@@ -1969,17 +2362,20 @@ __all__ = [
|
|
|
1969
2362
|
"VENDOR_PROVIDERS",
|
|
1970
2363
|
"VendorFieldClassification",
|
|
1971
2364
|
"VendorMeasure",
|
|
2365
|
+
"expand_place_key",
|
|
2366
|
+
"expand_same_as_figure",
|
|
1972
2367
|
"figure_places",
|
|
1973
2368
|
"figure_statement_vocabulary",
|
|
2369
|
+
"is_product_statement_measure_kind",
|
|
1974
2370
|
"not_stated",
|
|
1975
2371
|
"parse_figure_statement",
|
|
1976
2372
|
"parse_statements",
|
|
1977
2373
|
"render_figure_statement",
|
|
1978
|
-
"expand_place_key",
|
|
1979
2374
|
"render_place",
|
|
1980
2375
|
"render_statement_label",
|
|
1981
2376
|
"render_statements",
|
|
1982
|
-
"expand_same_as_figure",
|
|
1983
2377
|
"resolve_statements",
|
|
2378
|
+
"statement_measure_kinds",
|
|
1984
2379
|
"trailing_alignment",
|
|
2380
|
+
"validate_statement_entries",
|
|
1985
2381
|
]
|
|
File without changes
|
|
File without changes
|
{value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/tests/test_comps_manifest_display.py
RENAMED
|
File without changes
|
|
File without changes
|
{value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/tests/test_forward_ev_adjusted_ebitda.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/tests/test_two_stage_reconciliation.py
RENAMED
|
File without changes
|
|
File without changes
|
{value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core/conventions_ir_v1.py
RENAMED
|
File without changes
|
{value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core/decimal_wire.py
RENAMED
|
File without changes
|
{value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core/enterprise_value.py
RENAMED
|
File without changes
|
{value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core/formatting.py
RENAMED
|
File without changes
|
|
File without changes
|
{value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core/forward_pe.py
RENAMED
|
File without changes
|
{value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core/numeric_display.py
RENAMED
|
File without changes
|
{value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core/period_ref.py
RENAMED
|
File without changes
|
|
File without changes
|
{value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core/reconciliation.py
RENAMED
|
File without changes
|
{value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{value_semantics_core-2.2.0 → value_semantics_core-2.3.1}/value_semantics_core.egg-info/requires.txt
RENAMED
|
File without changes
|
|
File without changes
|