Repository navigation
Add members_of() to discover XBRL tags by standard concept - #2061
Conversation
dgunning
left a comment
There was a problem hiding this comment.
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.
|
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! |
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-levelmembers_of()now return a structured record for each matching key, using the existinglookup()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=Noneandidentity_status="unqualified". Feedback on that identity representation is welcome. TheMappingStore.get_company_concepts()docstring now clarifies that it queries the legacy store.Fixes #1423
Verification
0000731766-25-000063. The offline test checks that amount and verifies thatPremiumsEarnedNetappears inmembers_of("Revenue").Recorded on:
Nonechangelog.d/<id>.<section>.mdfragment, not an edit toCHANGELOG.mdAll 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
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
ValueErrorin the new validation path. After the switch toValidationError, I reran the failing check and the full fast suite.