Repository navigation
Add XBRL filter for filer-defined tags - #1992
Conversation
dgunning
left a comment
There was a problem hiding this comment.
Thanks for this. The filter does what it should on a filing whose schema is loaded: on Apple's FY2023 fixture it returns exactly the 77 aapl: facts, and the fast XBRL tests pass on the branch. There are two behaviours I'd like fixed before merging.
Stitched queries crash. XBRLS([...]).query().by_extension() raises AttributeError: 'StitchedFactsView' object has no attribute 'xbrl', because the method reads self._facts_view.xbrl, which only a single filing's query has. Either make it work across the stitched filings (each one's target namespaces) or raise a clear error saying it isn't supported on stitched queries.
A missing schema returns nothing, silently. XBRL.from_files(instance_file=...) without a schema gives 0 rows, and so does the Tesla fixture from your test when it's loaded with XBRL.from_directory() (0 of 1,059 facts), because that loader doesn't pick up the .xsd.xml file name. A user can't tell "this filer has no extension facts" apart from "the schema never loaded". When no target namespace is known, please raise an error that says the filing's schema wasn't loaded, rather than returning an empty result.
Two smaller things:
- Could you name the changelog fragment
1991.added.mdand give it a measured value and the issue reference? For example, Tesla's June 2024 10-Q (0001628280-24-032662) returning its $184 million digital-assets fact, then(GH #1991). by_extension()isn't mentioned in the docs yet. A short entry next to the other query filters indocs/api/xbrl.mdwould let people find it.
If the first two are in soon, this can still make 6.4.0.
dgunning
left a comment
There was a problem hiding this comment.
Thanks, this covers everything from my last review. Stitched queries now raise a clear NotImplementedError, and a missing schema raises ValidationError instead of returning nothing. That includes the Tesla fixture loaded with XBRL.from_directory(), which used to give 0 of 1,059 facts.
I ran it against a few filings outside the tests, and each returned only the filer's own prefix: JPMorgan's FY2024 10-K (1,631 of 7,778 facts, jpm), SAP's 20-F (1,169 of 4,102, sap) and NextEra's September 2025 10-Q (566 of 2,125, nee). Tesla's June 2024 10-Q gives 129 extension facts, with f-50 as tsla:DigitalAssetsNetNonCurrent at $184 million. The regression tests and the fast XBRL suite pass, and the branch merges cleanly with main.
from_directory() not picking up the .xsd.xml schema file is older than this PR, so I'll track it separately rather than hold this up. I'll merge it for 6.5.
What this changes
Adds
by_extension()to filing XBRL queries so users can retrieve facts tagged with concepts defined by the filer. The filter compares each fact’s namespace URI against the namespaces declared by the filing’s schemas. For example,filing.xbrl().query().by_extension().to_dataframe()returns the matching facts as a DataFrame.Fixes #1991
Verification
0001628280-24-032662, reports digital assets, net of $184 million. The test checks that the filter returns that filer-defined fact and excludesus-gaap:Assets.changelog.d/filer-defined-xbrl-tags.added.md.All 19 targeted XBRL tests passed, and the changelog check passed.
AI assistance