value-semantics-core 2.3.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.3.0 → value_semantics_core-2.3.1}/PKG-INFO +1 -1
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/pyproject.toml +1 -1
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/tests/test_figure_statement.py +59 -0
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/value_semantics_core/figure_statement.py +81 -15
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/value_semantics_core.egg-info/PKG-INFO +1 -1
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/README.md +0 -0
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/setup.cfg +0 -0
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/tests/test_comps_manifest_display.py +0 -0
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/tests/test_enterprise_value.py +0 -0
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/tests/test_forward_ev_adjusted_ebitda.py +0 -0
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/tests/test_forward_pe.py +0 -0
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/tests/test_ntm_forward_ev_adjusted_ebitda.py +0 -0
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/tests/test_ntm_forward_pe.py +0 -0
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/tests/test_numeric_display.py +0 -0
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/tests/test_two_stage_reconciliation.py +0 -0
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/value_semantics_core/__init__.py +0 -0
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/value_semantics_core/comps_manifest_display.py +0 -0
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/value_semantics_core/conventions_ir_v1.py +0 -0
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/value_semantics_core/decimal_wire.py +0 -0
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/value_semantics_core/enterprise_value.py +0 -0
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/value_semantics_core/formatting.py +0 -0
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/value_semantics_core/forward_ev_adjusted_ebitda.py +0 -0
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/value_semantics_core/forward_pe.py +0 -0
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/value_semantics_core/numeric_display.py +0 -0
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/value_semantics_core/period_ref.py +0 -0
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/value_semantics_core/quantity.py +0 -0
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/value_semantics_core/reconciliation.py +0 -0
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/value_semantics_core.egg-info/SOURCES.txt +0 -0
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/value_semantics_core.egg-info/dependency_links.txt +0 -0
- {value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/value_semantics_core.egg-info/requires.txt +0 -0
- {value_semantics_core-2.3.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.3.
|
|
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"]
|
|
@@ -839,3 +839,62 @@ def test_validate_statement_entries_resolves_complement_and_cross_row_place_inpu
|
|
|
839
839
|
with pytest.raises(StatementsRefused) as exc_cycle:
|
|
840
840
|
validate_statement_entries(cyclic_cross_row)
|
|
841
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))
|
{value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/value_semantics_core/figure_statement.py
RENAMED
|
@@ -1723,14 +1723,18 @@ def _witness_places_for_entry(
|
|
|
1723
1723
|
entry for entry in entries if _patterns_overlap(target.pattern, entry.pattern)
|
|
1724
1724
|
]
|
|
1725
1725
|
max_depth = max(len(entry.pattern) for entry in overlapping)
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
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
1731
|
for entry in overlapping
|
|
1732
1732
|
)
|
|
1733
|
-
|
|
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)
|
|
1734
1738
|
if depth == 0:
|
|
1735
1739
|
return [()]
|
|
1736
1740
|
steps_by_pos: list[list[str | int]] = []
|
|
@@ -1764,13 +1768,24 @@ def _witness_places_for_entry(
|
|
|
1764
1768
|
for item in seg:
|
|
1765
1769
|
if isinstance(item, str) and item not in str_steps:
|
|
1766
1770
|
str_steps.append(item)
|
|
1771
|
+
named_index = bool(int_steps)
|
|
1767
1772
|
if has_wildcard_int and not int_steps:
|
|
1768
1773
|
int_steps.append(0)
|
|
1769
|
-
|
|
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:
|
|
1770
1785
|
fresh = _fresh_member_name(excluded_names | set(str_steps))
|
|
1771
1786
|
str_steps.append(fresh)
|
|
1772
1787
|
raw_steps: list[str | int] = [*int_steps, *str_steps]
|
|
1773
|
-
if
|
|
1788
|
+
if not beyond:
|
|
1774
1789
|
raw_steps = [
|
|
1775
1790
|
step for step in raw_steps if _segment_covers(target.pattern[pos], step)
|
|
1776
1791
|
]
|
|
@@ -1844,6 +1859,28 @@ def _try_resolve_entry_place(
|
|
|
1844
1859
|
return statement, []
|
|
1845
1860
|
|
|
1846
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
|
+
|
|
1847
1884
|
def _resolve_witness_statements(
|
|
1848
1885
|
entries: Sequence[StatementEntry],
|
|
1849
1886
|
) -> dict[Place, FigureStatement]:
|
|
@@ -1854,11 +1891,22 @@ def _resolve_witness_statements(
|
|
|
1854
1891
|
best_missing_place: Place = witnesses[0] if witnesses else ()
|
|
1855
1892
|
best_missing_fact: str = "measure"
|
|
1856
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
|
|
1857
1900
|
for place in witnesses:
|
|
1858
1901
|
if place in resolved:
|
|
1859
1902
|
complete_count += 1
|
|
1860
1903
|
continue
|
|
1861
|
-
|
|
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
|
|
1862
1910
|
if statement is None:
|
|
1863
1911
|
present_count = len(_FACTS) - len(missing)
|
|
1864
1912
|
if present_count > best_present_count:
|
|
@@ -1869,6 +1917,8 @@ def _resolve_witness_statements(
|
|
|
1869
1917
|
resolved[place] = statement
|
|
1870
1918
|
complete_count += 1
|
|
1871
1919
|
if complete_count == 0:
|
|
1920
|
+
if first_refusal is not None:
|
|
1921
|
+
raise first_refusal
|
|
1872
1922
|
raise StatementsRefused(
|
|
1873
1923
|
"figure_not_stated",
|
|
1874
1924
|
"no entry covering the figure states this fact",
|
|
@@ -1882,12 +1932,28 @@ def _resolve_witness_statements(
|
|
|
1882
1932
|
edges: dict[Place, list[Place]] = {}
|
|
1883
1933
|
|
|
1884
1934
|
def resolve_on_demand(target_place: Place) -> FigureStatement | None:
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
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
|
|
1891
1957
|
|
|
1892
1958
|
while queue:
|
|
1893
1959
|
place = queue.popleft()
|
|
File without changes
|
|
File without changes
|
{value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/tests/test_comps_manifest_display.py
RENAMED
|
File without changes
|
|
File without changes
|
{value_semantics_core-2.3.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.3.0 → value_semantics_core-2.3.1}/tests/test_two_stage_reconciliation.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/value_semantics_core/conventions_ir_v1.py
RENAMED
|
File without changes
|
{value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/value_semantics_core/decimal_wire.py
RENAMED
|
File without changes
|
{value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/value_semantics_core/enterprise_value.py
RENAMED
|
File without changes
|
{value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/value_semantics_core/formatting.py
RENAMED
|
File without changes
|
|
File without changes
|
{value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/value_semantics_core/forward_pe.py
RENAMED
|
File without changes
|
{value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/value_semantics_core/numeric_display.py
RENAMED
|
File without changes
|
{value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/value_semantics_core/period_ref.py
RENAMED
|
File without changes
|
|
File without changes
|
{value_semantics_core-2.3.0 → value_semantics_core-2.3.1}/value_semantics_core/reconciliation.py
RENAMED
|
File without changes
|
{value_semantics_core-2.3.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.3.0 → value_semantics_core-2.3.1}/value_semantics_core.egg-info/requires.txt
RENAMED
|
File without changes
|
|
File without changes
|