Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,15 @@ def get_depth(tag: str) -> int:
children_detail = " + ".join(contributing_children)

if p_val is None:
# Operating income cannot be inferred from a lone revenue or
# expense row. Without both sides of the operating equation,
# a rollup would manufacture a misleading 100% margin (or its
# expense-only equivalent).
if (
parent_tag == "total_operating_income"
and len(contributing_children) < 2
):
continue
parent_row.values[date] = children_sum
parent_row.sources[date] = f"imputed-rollup: {children_detail}"
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,14 @@
"tag": "ShortTermDebtCurrent",
"namespace": "us-gaap"
},
{
"tag": "NotesAndLoansPayable",
"namespace": "us-gaap"
},
{
"tag": "OtherShortTermBorrowings",
"namespace": "us-gaap"
},
{
"tag": "ShorttermBorrowings",
"namespace": "ifrs-full"
Expand Down Expand Up @@ -1124,6 +1132,18 @@
"tag": "CurrentPortionOfLongTermDebt",
"namespace": "us-gaap"
},
{
"tag": "LongTermDebtAndCapitalLeaseObligationsCurrent",
"namespace": "us-gaap"
},
{
"tag": "LongTermDebtCurrentMaturities",
"namespace": "us-gaap"
},
{
"tag": "DebtCurrent",
"namespace": "us-gaap"
},
{
"tag": "CurrentPortionOfNoncurrentBorrowings",
"namespace": "ifrs-full"
Expand Down Expand Up @@ -3627,6 +3647,14 @@
{
"tag": "ShortTermDebtCurrent",
"namespace": "us-gaap"
},
{
"tag": "NotesAndLoansPayable",
"namespace": "us-gaap"
},
{
"tag": "OtherShortTermBorrowings",
"namespace": "us-gaap"
}
]
},
Expand All @@ -3650,6 +3678,18 @@
{
"tag": "CurrentPortionOfLongTermDebt",
"namespace": "us-gaap"
},
{
"tag": "LongTermDebtAndCapitalLeaseObligationsCurrent",
"namespace": "us-gaap"
},
{
"tag": "LongTermDebtCurrentMaturities",
"namespace": "us-gaap"
},
{
"tag": "DebtCurrent",
"namespace": "us-gaap"
}
]
},
Expand Down Expand Up @@ -3757,12 +3797,6 @@
"unit": "monetary",
"period_type": "instant",
"xbrl_tags": [
{
"tag": "OtherShortTermBorrowings",
"namespace": "us-gaap",
"first_year": 2011,
"last_year": 2026
},
{
"tag": "OtherLiabilitiesCurrent",
"namespace": "us-gaap",
Expand Down Expand Up @@ -5870,6 +5904,14 @@
"tag": "ShortTermDebtCurrent",
"namespace": "us-gaap"
},
{
"tag": "NotesAndLoansPayable",
"namespace": "us-gaap"
},
{
"tag": "OtherShortTermBorrowings",
"namespace": "us-gaap"
},
{
"tag": "ShorttermBorrowings",
"namespace": "ifrs-full"
Expand Down Expand Up @@ -5913,6 +5955,18 @@
"tag": "CurrentPortionOfLongTermDebt",
"namespace": "us-gaap"
},
{
"tag": "LongTermDebtAndCapitalLeaseObligationsCurrent",
"namespace": "us-gaap"
},
{
"tag": "LongTermDebtCurrentMaturities",
"namespace": "us-gaap"
},
{
"tag": "DebtCurrent",
"namespace": "us-gaap"
},
{
"tag": "CurrentPortionOfNoncurrentBorrowings",
"namespace": "ifrs-full"
Expand Down Expand Up @@ -8341,6 +8395,14 @@
"tag": "ShortTermDebtCurrent",
"namespace": "us-gaap"
},
{
"tag": "NotesAndLoansPayable",
"namespace": "us-gaap"
},
{
"tag": "OtherShortTermBorrowings",
"namespace": "us-gaap"
},
{
"tag": "ShorttermBorrowings",
"namespace": "ifrs-full"
Expand Down Expand Up @@ -8371,6 +8433,18 @@
{
"tag": "CurrentPortionOfLongTermDebt",
"namespace": "us-gaap"
},
{
"tag": "LongTermDebtAndCapitalLeaseObligationsCurrent",
"namespace": "us-gaap"
},
{
"tag": "LongTermDebtCurrentMaturities",
"namespace": "us-gaap"
},
{
"tag": "DebtCurrent",
"namespace": "us-gaap"
}
]
},
Expand Down Expand Up @@ -8486,12 +8560,6 @@
"unit": "monetary",
"period_type": "instant",
"xbrl_tags": [
{
"tag": "OtherShortTermBorrowings",
"namespace": "us-gaap",
"first_year": 2011,
"last_year": 2026
},
{
"tag": "OtherLiabilitiesCurrent",
"namespace": "us-gaap",
Expand Down
68 changes: 68 additions & 0 deletions openbb_platform/providers/sec/tests/test_company_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
from openbb_sec.utils.company_facts import resolve_company_facts
from openbb_sec.utils.statement_schema import StatementSchema
from openbb_sec.utils.statement_schema._detection import get_filing_dates
from openbb_sec.utils.statement_schema._imputation import (
_apply_hierarchical_articulation,
)
from openbb_sec.utils.statement_schema._types import RowResult

_FIXTURE_DIR = Path(__file__).parent / "record"

Expand Down Expand Up @@ -125,6 +129,70 @@ def test_company_type_detection(schema):
assert schema.detect_type(diversified["facts"]) == "diversified"


@pytest.mark.parametrize(
"profile", ["industrial", "financial", "diversified", "insurance"]
)
def test_current_debt_tag_mappings(schema, profile):
"""Common current-debt spellings map consistently across profiles."""
rows = schema._statements["balance_sheet"][profile] # pylint: disable=W0212
tags_by_row = {
row["tag"]: {item["tag"] for item in row["xbrl_tags"]} for row in rows
}

assert {"NotesAndLoansPayable", "OtherShortTermBorrowings"} <= tags_by_row[
"short_term_debt"
]
assert {
"LongTermDebtAndCapitalLeaseObligationsCurrent",
"LongTermDebtCurrentMaturities",
"DebtCurrent",
} <= tags_by_row["current_portion_of_long_term_debt"]

for row in rows:
if row["tag"] != "short_term_debt":
assert "OtherShortTermBorrowings" not in {
item["tag"] for item in row["xbrl_tags"]
}


def test_operating_income_not_rolled_up_from_single_child():
"""A lone revenue row must not imply a 100% operating margin."""
date = "2025-12-31"
rows = [
RowResult(
tag="total_revenue",
label="Total Revenue",
description="",
parent="total_operating_income",
sequence=1,
factor="+",
balance="credit",
unit="monetary",
period_type="duration",
values={date: 1000.0},
sources={date: "us-gaap:Revenues"},
),
RowResult(
tag="total_operating_income",
label="Total Operating Income",
description="",
parent=None,
sequence=2,
factor="+",
balance="credit",
unit="monetary",
period_type="duration",
values={},
sources={},
),
]

_apply_hierarchical_articulation(rows, {date})

assert date not in rows[1].values
assert date not in rows[1].sources


def test_basic_extraction_and_imputation():
def anchor_tags(year):
return [
Expand Down