value-semantics-core 2.2.0__tar.gz → 2.3.0__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.0}/PKG-INFO +1 -1
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/pyproject.toml +1 -1
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/tests/test_figure_statement.py +181 -17
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/value_semantics_core/__init__.py +28 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/value_semantics_core/figure_statement.py +360 -30
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/value_semantics_core.egg-info/PKG-INFO +1 -1
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/README.md +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/setup.cfg +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/tests/test_comps_manifest_display.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/tests/test_enterprise_value.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/tests/test_forward_ev_adjusted_ebitda.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/tests/test_forward_pe.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/tests/test_ntm_forward_ev_adjusted_ebitda.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/tests/test_ntm_forward_pe.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/tests/test_numeric_display.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/tests/test_two_stage_reconciliation.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/value_semantics_core/comps_manifest_display.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/value_semantics_core/conventions_ir_v1.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/value_semantics_core/decimal_wire.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/value_semantics_core/enterprise_value.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/value_semantics_core/formatting.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/value_semantics_core/forward_ev_adjusted_ebitda.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/value_semantics_core/forward_pe.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/value_semantics_core/numeric_display.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/value_semantics_core/period_ref.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/value_semantics_core/quantity.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/value_semantics_core/reconciliation.py +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/value_semantics_core.egg-info/SOURCES.txt +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/value_semantics_core.egg-info/dependency_links.txt +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/value_semantics_core.egg-info/requires.txt +0 -0
- {value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/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.0"
|
|
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,136 @@ 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"
|
|
@@ -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.0}/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,285 @@ 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
|
+
needs_leaf_key = any(
|
|
1727
|
+
isinstance(entry.measure, dict)
|
|
1728
|
+
and entry.measure.get("field") == {"kind": "place_key"}
|
|
1729
|
+
and len(entry.pattern) == max_depth
|
|
1730
|
+
and (not entry.pattern or _is_int_pattern_segment(entry.pattern[-1]))
|
|
1731
|
+
for entry in overlapping
|
|
1732
|
+
)
|
|
1733
|
+
depth = max_depth + (1 if needs_leaf_key else 0)
|
|
1734
|
+
if depth == 0:
|
|
1735
|
+
return [()]
|
|
1736
|
+
steps_by_pos: list[list[str | int]] = []
|
|
1737
|
+
for pos in range(depth):
|
|
1738
|
+
segs = [entry.pattern[pos] for entry in overlapping if pos < len(entry.pattern)]
|
|
1739
|
+
if not segs:
|
|
1740
|
+
steps_by_pos.append(["__field__"])
|
|
1741
|
+
continue
|
|
1742
|
+
int_steps: list[int] = []
|
|
1743
|
+
str_steps: list[str] = []
|
|
1744
|
+
excluded_names: set[str] = set()
|
|
1745
|
+
has_wildcard_int = False
|
|
1746
|
+
has_complement = False
|
|
1747
|
+
for seg in segs:
|
|
1748
|
+
if seg is None:
|
|
1749
|
+
has_wildcard_int = True
|
|
1750
|
+
elif isinstance(seg, int):
|
|
1751
|
+
if seg not in int_steps:
|
|
1752
|
+
int_steps.append(seg)
|
|
1753
|
+
elif isinstance(seg, str):
|
|
1754
|
+
if seg not in str_steps:
|
|
1755
|
+
str_steps.append(seg)
|
|
1756
|
+
elif isinstance(seg, MemberComplement):
|
|
1757
|
+
has_complement = True
|
|
1758
|
+
excluded_names.update(seg.names)
|
|
1759
|
+
elif isinstance(seg, tuple) and isinstance(seg[0], int):
|
|
1760
|
+
for item in seg:
|
|
1761
|
+
if isinstance(item, int) and item not in int_steps:
|
|
1762
|
+
int_steps.append(item)
|
|
1763
|
+
elif isinstance(seg, tuple) and isinstance(seg[0], str):
|
|
1764
|
+
for item in seg:
|
|
1765
|
+
if isinstance(item, str) and item not in str_steps:
|
|
1766
|
+
str_steps.append(item)
|
|
1767
|
+
if has_wildcard_int and not int_steps:
|
|
1768
|
+
int_steps.append(0)
|
|
1769
|
+
if has_complement:
|
|
1770
|
+
fresh = _fresh_member_name(excluded_names | set(str_steps))
|
|
1771
|
+
str_steps.append(fresh)
|
|
1772
|
+
raw_steps: list[str | int] = [*int_steps, *str_steps]
|
|
1773
|
+
if pos < len(target.pattern):
|
|
1774
|
+
raw_steps = [
|
|
1775
|
+
step for step in raw_steps if _segment_covers(target.pattern[pos], step)
|
|
1776
|
+
]
|
|
1777
|
+
steps_by_pos.append(raw_steps)
|
|
1778
|
+
return [tuple(combo) for combo in itertools.product(*steps_by_pos)]
|
|
1779
|
+
|
|
1780
|
+
|
|
1781
|
+
def _try_resolve_entry_place(
|
|
1782
|
+
place: Place,
|
|
1783
|
+
entries: Sequence[StatementEntry],
|
|
1784
|
+
) -> tuple[FigureStatement | None, list[str]]:
|
|
1785
|
+
union: dict[str, Any] = {}
|
|
1786
|
+
owners: dict[tuple[str, ...], int] = {}
|
|
1787
|
+
|
|
1788
|
+
def conflict(first: int, second: int, key: str, place: Place = place) -> None:
|
|
1789
|
+
raise StatementsRefused(
|
|
1790
|
+
"conflicting_facts",
|
|
1791
|
+
"two covering entries state one key differently",
|
|
1792
|
+
place=place,
|
|
1793
|
+
entries=(first, second),
|
|
1794
|
+
ats=(entries[first].at, entries[second].at),
|
|
1795
|
+
fact=key,
|
|
1796
|
+
)
|
|
1797
|
+
|
|
1798
|
+
for index, entry in enumerate(entries):
|
|
1799
|
+
if _covers(entry.pattern, place):
|
|
1800
|
+
_merge(
|
|
1801
|
+
union,
|
|
1802
|
+
entry.facts(),
|
|
1803
|
+
entry=index,
|
|
1804
|
+
path=(),
|
|
1805
|
+
owners=owners,
|
|
1806
|
+
conflict=conflict,
|
|
1807
|
+
)
|
|
1808
|
+
missing = [fact for fact in _FACTS if fact not in union]
|
|
1809
|
+
if missing:
|
|
1810
|
+
return None, missing
|
|
1811
|
+
try:
|
|
1812
|
+
statement = FigureStatement.model_validate(union)
|
|
1813
|
+
except ValidationError as exc:
|
|
1814
|
+
first = exc.errors(include_url=False)[0]
|
|
1815
|
+
code: StatementsRefusalCode = (
|
|
1816
|
+
"unknown_key" if first["type"] == "extra_forbidden" else "statement_invalid"
|
|
1817
|
+
)
|
|
1818
|
+
raise StatementsRefused(
|
|
1819
|
+
code,
|
|
1820
|
+
str(first["msg"]),
|
|
1821
|
+
place=place,
|
|
1822
|
+
fact=".".join(str(part) for part in first["loc"]),
|
|
1823
|
+
) from exc
|
|
1824
|
+
if isinstance(statement.period, SameAsFigure):
|
|
1825
|
+
raise StatementsRefused(
|
|
1826
|
+
"statement_invalid",
|
|
1827
|
+
"a figure's own period is not same_as_figure",
|
|
1828
|
+
place=place,
|
|
1829
|
+
fact="period",
|
|
1830
|
+
)
|
|
1831
|
+
measure = statement.measure
|
|
1832
|
+
if (
|
|
1833
|
+
isinstance(measure, VendorMeasure)
|
|
1834
|
+
and isinstance(measure.field, PlaceKey)
|
|
1835
|
+
and (not place or not isinstance(place[-1], str))
|
|
1836
|
+
):
|
|
1837
|
+
raise StatementsRefused(
|
|
1838
|
+
"place_key_not_a_key",
|
|
1839
|
+
"place_key names the vendor's field by the string at the figure's last "
|
|
1840
|
+
"segment; this figure's last segment is a list index",
|
|
1841
|
+
place=place,
|
|
1842
|
+
fact="measure.field",
|
|
1843
|
+
)
|
|
1844
|
+
return statement, []
|
|
1845
|
+
|
|
1846
|
+
|
|
1847
|
+
def _resolve_witness_statements(
|
|
1848
|
+
entries: Sequence[StatementEntry],
|
|
1849
|
+
) -> dict[Place, FigureStatement]:
|
|
1850
|
+
resolved: dict[Place, FigureStatement] = {}
|
|
1851
|
+
for target_index, target in enumerate(entries):
|
|
1852
|
+
witnesses = _witness_places_for_entry(target, entries)
|
|
1853
|
+
complete_count = 0
|
|
1854
|
+
best_missing_place: Place = witnesses[0] if witnesses else ()
|
|
1855
|
+
best_missing_fact: str = "measure"
|
|
1856
|
+
best_present_count = -1
|
|
1857
|
+
for place in witnesses:
|
|
1858
|
+
if place in resolved:
|
|
1859
|
+
complete_count += 1
|
|
1860
|
+
continue
|
|
1861
|
+
statement, missing = _try_resolve_entry_place(place, entries)
|
|
1862
|
+
if statement is None:
|
|
1863
|
+
present_count = len(_FACTS) - len(missing)
|
|
1864
|
+
if present_count > best_present_count:
|
|
1865
|
+
best_present_count = present_count
|
|
1866
|
+
best_missing_place = place
|
|
1867
|
+
best_missing_fact = missing[0]
|
|
1868
|
+
continue
|
|
1869
|
+
resolved[place] = statement
|
|
1870
|
+
complete_count += 1
|
|
1871
|
+
if complete_count == 0:
|
|
1872
|
+
raise StatementsRefused(
|
|
1873
|
+
"figure_not_stated",
|
|
1874
|
+
"no entry covering the figure states this fact",
|
|
1875
|
+
place=best_missing_place,
|
|
1876
|
+
entries=(target_index,),
|
|
1877
|
+
ats=(target.at,),
|
|
1878
|
+
fact=best_missing_fact,
|
|
1879
|
+
)
|
|
1880
|
+
queue: deque[Place] = deque(resolved.keys())
|
|
1881
|
+
walked: set[Place] = set()
|
|
1882
|
+
edges: dict[Place, list[Place]] = {}
|
|
1883
|
+
|
|
1884
|
+
def resolve_on_demand(target_place: Place) -> FigureStatement | None:
|
|
1885
|
+
statement, _missing = _try_resolve_entry_place(target_place, entries)
|
|
1886
|
+
if statement is None:
|
|
1887
|
+
return None
|
|
1888
|
+
resolved[target_place] = statement
|
|
1889
|
+
queue.append(target_place)
|
|
1890
|
+
return statement
|
|
1891
|
+
|
|
1892
|
+
while queue:
|
|
1893
|
+
place = queue.popleft()
|
|
1894
|
+
if place in walked:
|
|
1895
|
+
continue
|
|
1896
|
+
walked.add(place)
|
|
1897
|
+
_resolved_stmt, edges[place] = _resolve_inputs(
|
|
1898
|
+
resolved[place],
|
|
1899
|
+
place,
|
|
1900
|
+
resolved,
|
|
1901
|
+
on_missing_place=resolve_on_demand,
|
|
1902
|
+
)
|
|
1903
|
+
_refuse_input_cycles(edges)
|
|
1904
|
+
return resolved
|
|
1905
|
+
|
|
1906
|
+
|
|
1907
|
+
def validate_statement_entries(value: object) -> tuple[StatementEntry, ...]:
|
|
1908
|
+
"""Parse and validate a row's ``statements`` entries without requiring the raw result.
|
|
1909
|
+
|
|
1910
|
+
Every entry must pass ``parse_statements``, conflict with no overlapping
|
|
1911
|
+
entry, and participate in at least one complete, valid ``FigureStatement``
|
|
1912
|
+
(checking ``measure``, ``period``, ``basis``, ``place_key``, inline inputs,
|
|
1913
|
+
and in-answer ``place`` references across witness places).
|
|
1914
|
+
"""
|
|
1915
|
+
|
|
1916
|
+
entries = parse_statements(value)
|
|
1917
|
+
_resolve_witness_statements(entries)
|
|
1918
|
+
return tuple(entries)
|
|
1919
|
+
|
|
1920
|
+
|
|
1921
|
+
def statement_measure_kinds(entries: Sequence[StatementEntry]) -> frozenset[MeasureKind]:
|
|
1922
|
+
"""The typed ``MeasureKind`` set across a validated row's ``StatementEntry`` sequence."""
|
|
1923
|
+
|
|
1924
|
+
resolved = _resolve_witness_statements(entries)
|
|
1925
|
+
return frozenset(statement.measure.kind for statement in resolved.values())
|
|
1926
|
+
|
|
1927
|
+
|
|
1928
|
+
def is_product_statement_measure_kind(kind: object) -> bool:
|
|
1929
|
+
"""True when ``kind`` is a product-authored non-evidence measure kind."""
|
|
1930
|
+
|
|
1931
|
+
return isinstance(kind, str) and kind in PRODUCT_STATEMENT_MEASURE_KINDS
|
|
1932
|
+
|
|
1933
|
+
|
|
1619
1934
|
def _refuse_input_cycles(edges: dict[Place, list[Place]]) -> None:
|
|
1620
1935
|
"""Refuse a figure computed, through its in-answer inputs at any depth, from itself.
|
|
1621
1936
|
|
|
@@ -1720,6 +2035,13 @@ def _measure_label(measure: Mapping[str, Any]) -> str:
|
|
|
1720
2035
|
parts.append("the model")
|
|
1721
2036
|
if measure.get("model_item_id"):
|
|
1722
2037
|
parts.append(f"item {measure.get('model_item_id')}")
|
|
2038
|
+
elif kind == "skill_artifact":
|
|
2039
|
+
if measure.get("skill") and measure.get("artifact_id"):
|
|
2040
|
+
parts.append(f"{measure.get('skill')} artifact {measure.get('artifact_id')}")
|
|
2041
|
+
else:
|
|
2042
|
+
parts.append("skill artifact")
|
|
2043
|
+
if measure.get("field"):
|
|
2044
|
+
parts.append(f"field {measure.get('field')}")
|
|
1723
2045
|
elif kind == "broker_reported":
|
|
1724
2046
|
parts.append(f"{measure.get('broker')}'s {measure.get('field') or 'record'}")
|
|
1725
2047
|
if measure.get("account"):
|
|
@@ -1888,6 +2210,7 @@ def figure_statement_vocabulary() -> dict[str, Any]:
|
|
|
1888
2210
|
|
|
1889
2211
|
return {
|
|
1890
2212
|
"measure_kinds": list(MEASURE_KINDS),
|
|
2213
|
+
"product_statement_measure_kinds": list(get_args(ProductStatementMeasureKind)),
|
|
1891
2214
|
"period_kinds": list(PERIOD_KINDS),
|
|
1892
2215
|
"period_statuses": list(PERIOD_STATUSES),
|
|
1893
2216
|
"period_built": list(PERIOD_BUILT_VALUES),
|
|
@@ -1935,6 +2258,7 @@ __all__ = [
|
|
|
1935
2258
|
"InlineStatement",
|
|
1936
2259
|
"IssuerFiledMeasure",
|
|
1937
2260
|
"MEASURE_KINDS",
|
|
2261
|
+
"MeasureKind",
|
|
1938
2262
|
"MemberComplement",
|
|
1939
2263
|
"ModelVersion",
|
|
1940
2264
|
"NOT_STATED_PHRASES",
|
|
@@ -1946,17 +2270,20 @@ __all__ = [
|
|
|
1946
2270
|
"PERIOD_KINDS",
|
|
1947
2271
|
"PERIOD_STATUSES",
|
|
1948
2272
|
"PLACE_KEY_PHRASE",
|
|
2273
|
+
"PRODUCT_STATEMENT_MEASURE_KINDS",
|
|
1949
2274
|
"Pattern",
|
|
1950
2275
|
"PlaceKey",
|
|
1951
2276
|
"PeriodBuilt",
|
|
1952
2277
|
"PeriodStatus",
|
|
1953
2278
|
"Place",
|
|
1954
2279
|
"ProductModelMeasure",
|
|
2280
|
+
"ProductStatementMeasureKind",
|
|
1955
2281
|
"RECORDED_DEFINITION_PHRASES",
|
|
1956
2282
|
"RECORDED_DEFINITION_SEMANTICS",
|
|
1957
2283
|
"RecordedDefinition",
|
|
1958
2284
|
"RowPlaceReference",
|
|
1959
2285
|
"SameAsFigure",
|
|
2286
|
+
"SkillArtifactMeasure",
|
|
1960
2287
|
"StatedPeriod",
|
|
1961
2288
|
"STATEMENTS_REFUSAL_CODES",
|
|
1962
2289
|
"StatementEntry",
|
|
@@ -1969,17 +2296,20 @@ __all__ = [
|
|
|
1969
2296
|
"VENDOR_PROVIDERS",
|
|
1970
2297
|
"VendorFieldClassification",
|
|
1971
2298
|
"VendorMeasure",
|
|
2299
|
+
"expand_place_key",
|
|
2300
|
+
"expand_same_as_figure",
|
|
1972
2301
|
"figure_places",
|
|
1973
2302
|
"figure_statement_vocabulary",
|
|
2303
|
+
"is_product_statement_measure_kind",
|
|
1974
2304
|
"not_stated",
|
|
1975
2305
|
"parse_figure_statement",
|
|
1976
2306
|
"parse_statements",
|
|
1977
2307
|
"render_figure_statement",
|
|
1978
|
-
"expand_place_key",
|
|
1979
2308
|
"render_place",
|
|
1980
2309
|
"render_statement_label",
|
|
1981
2310
|
"render_statements",
|
|
1982
|
-
"expand_same_as_figure",
|
|
1983
2311
|
"resolve_statements",
|
|
2312
|
+
"statement_measure_kinds",
|
|
1984
2313
|
"trailing_alignment",
|
|
2314
|
+
"validate_statement_entries",
|
|
1985
2315
|
]
|
|
File without changes
|
|
File without changes
|
{value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/tests/test_comps_manifest_display.py
RENAMED
|
File without changes
|
|
File without changes
|
{value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/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.0}/tests/test_two_stage_reconciliation.py
RENAMED
|
File without changes
|
|
File without changes
|
{value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/value_semantics_core/conventions_ir_v1.py
RENAMED
|
File without changes
|
{value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/value_semantics_core/decimal_wire.py
RENAMED
|
File without changes
|
{value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/value_semantics_core/enterprise_value.py
RENAMED
|
File without changes
|
{value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/value_semantics_core/formatting.py
RENAMED
|
File without changes
|
|
File without changes
|
{value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/value_semantics_core/forward_pe.py
RENAMED
|
File without changes
|
{value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/value_semantics_core/numeric_display.py
RENAMED
|
File without changes
|
{value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/value_semantics_core/period_ref.py
RENAMED
|
File without changes
|
|
File without changes
|
{value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/value_semantics_core/reconciliation.py
RENAMED
|
File without changes
|
{value_semantics_core-2.2.0 → value_semantics_core-2.3.0}/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.0}/value_semantics_core.egg-info/requires.txt
RENAMED
|
File without changes
|
|
File without changes
|