Skip to content

Add members_of() to discover XBRL tags by standard concept - #2061

Merged
dgunning merged 2 commits into
dgunning:mainfrom
arjunarun65164:feat-1423-members-of
Nov 28, 2026
Merged

dgunning merged 2 commits into
dgunning:mainfrom
arjunarun65164:feat-1423-members-of

Conversation

@arjunarun65164

Copy link
Copy Markdown
Contributor

What this changes

Callers could look up an XBRL tag, but there was no public API to list the stored tags that map to a standard concept such as Revenue. ReverseIndex.members_of() and the module-level members_of() now return a structured record for each matching key, using the existing lookup() rules for industry overrides, exclusions, and total guards.

Each record preserves the exact stored key and the full lookup result, including all surviving candidates and mapping metadata. Bare keys with unknown taxonomy return qualified_tag=None and identity_status="unqualified". Feedback on that identity representation is welcome. The MappingStore.get_company_concepts() docstring now clarifies that it queries the legacy store.

Fixes #1423

Verification

  • Ground truth: I verified that UnitedHealth Group reported $308,810 million in 2024 premiums in its Form 10-K, accession 0000731766-25-000063. The offline test checks that amount and verifies that PremiumsEarnedNet appears in members_of("Revenue").
    Recorded on:
  • Silence check: bad or missing input produces a useful error, not None
  • Docs: any documented example this touches still runs
  • Changelog: a changelog.d/<id>.<section>.md fragment, not an edit to CHANGELOG.md

All 15 feature test cases passed. The full parallel fast suite passed after switching the invalid-identifier path to EdgarTools’ ValidationError. Ruff lint and the test file’s format check also passed.

AI assistance

  • Assisted. Tool and model: OpenAI Codex, GPT-6.2-Sol default

Working context

We wrote the offline tests first and confirmed they reached the missing API. The tests cover agreement with forward lookup, industry overrides, qualified and bare keys, result independence, and legacy compatibility. The full fast suite caught a plain ValueError in the new validation path. After the switch to ValidationError, I reran the failing check and the full fast suite.

@dgunning dgunning left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, it answers #1423 well. Building each member from lookup() means the family can never disagree with the forward lookup, and the tests pin that, including the industry overrides and the total guard. On the shipped index members_of("Revenue") returns 122 tags in about 5 ms, and the UnitedHealth check is a good ground truth.

You asked for feedback on the identity representation. On the shipped data, 120 of the 122 Revenue members are bare keys, so qualified_tag is None and identity_status is "unqualified" for nearly every row. identity_status only restates whether qualified_tag is None, so I'd drop it and keep qualified_tag alone. That's one less public field to support, and the docstring can say that bare keys have no qualification.

The other thing I'd like is a more helpful error for an unknown concept. The natural first guesses fail: members_of("Revenues"), members_of("NetIncomeLoss") and members_of("TotalAssets") all raise, while the identifiers are Revenue, NetIncome and Assets. The message says to use an identifier from MappingResult.standard_concepts, but there's no way to list them. Could the error suggest the closest known identifiers (difflib.get_close_matches over the known set would do), so "Revenues" points to "Revenue"?

One small docs note: the standardization page could say that members_of() reflects the XBRL statement mappings, which company.get_facts() doesn't use, so nobody expects it to explain get_revenue().

With those two changes I'm happy to merge it for 6.5.

@arjunarun65164

Copy link
Copy Markdown
Contributor Author

I've updated the codebase to reflect those changes. Happy to update the PR description to reflect the revised API and test cases as well!

@dgunning
dgunning merged commit 31371d4 into dgunning:main Nov 28, 2026
13 checks passed
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.

[FEATURE] Add a public members_of(standard_concept) to list the XBRL tags in a standardization family

2 participants