Skip to content

Parse dimensions from xbrli:scenario as well as xbrli:segment - #179

Open
DMZ22 wants to merge 1 commit into
manusimidt:mainfrom
DMZ22:esef-scenario-dimensions
Open

Parse dimensions from xbrli:scenario as well as xbrli:segment#179
DMZ22 wants to merge 1 commit into
manusimidt:mainfrom
DMZ22:esef-scenario-dimensions

Conversation

@DMZ22

@DMZ22 DMZ22 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Closes #159.

_parse_context_elements reads dimensional information only from xbrli:entity/xbrli:segment. Across the whole of instance.py before this change: segment appears 14 times, explicitMember 3, typedMember 3, and scenario zero times.

XBRL 2.1 allows a context to carry dimensions in either container — xbrli:segment, which is a child of xbrli:entity, or xbrli:scenario, which is a direct child of the context. US SEC filings generally use segment, which is why they parse correctly, while ESEF and other IFRS filings use scenario. That is why the reporter saw len(fact.context.segments) == 0 for roughly 20 European filers while US filings were fine.

The two are meant to behave identically, so rather than duplicating the ~50-line explicitMember/typedMember block I extracted it into _parse_dimensions(container, context, ns_map, taxonomy, taxParser) and call it for both paths:

for container_path in ("xbrli:entity/xbrli:segment", "xbrli:scenario"):
    container = context_elem.find(container_path, NAME_SPACES)
    if container is not None:
        _parse_dimensions(container, context, ns_map, taxonomy, taxParser)

The extracted body is unchanged apart from segment.findall becoming container.findall, so segment-based filings keep behaving exactly as before. Members from both containers land in context.segments, which keeps the existing public attribute and Fact.to_dict()'s dimensions mapping working untouched.

Tests. tests/test_context_dimensions.py is new and runs fully offline — the existing instance fixtures import a remote FASB schema, so instead of adding another network-dependent fixture I drive _parse_context_elements directly with a stub taxonomy. It covers an explicit member in segment, an explicit member in scenario, a typed member in scenario, a context carrying both containers at once, and a context with no dimensions.

Reverting instance.py while keeping the tests fails exactly the three scenario cases; the segment and no-dimension cases pass either way, deliberately, so they catch any regression to the existing path. The offline suite (test_context_dimensions, test_transformation, test_uri_helper) is 8 passed.

One thing I could not do locally: the network-backed tests in test_local_instance.py fetch xbrl.fasb.org, so I have not run those here — they exercise a code path this change does not alter, but worth a look in CI.

XBRL 2.1 lets a context carry dimensional information in either
xbrli:segment, a child of xbrli:entity, or xbrli:scenario, a direct child
of the context. Only segment was read, so every ESEF filing came back with
len(fact.context.segments) == 0 while US SEC filings parsed fine.

The explicitMember/typedMember block is extracted into _parse_dimensions
and run for both containers, so the two are handled identically.
@manusimidt
manusimidt self-requested a review July 26, 2026 07:47
@manusimidt manusimidt self-assigned this Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ESEF reports have no dimensions

2 participants