Add ISO 4217 currency column to XBRL facts DataFrame (#850)#851
Open
gaoflow wants to merge 1 commit into
Open
Conversation
xbrl().facts.to_dataframe() exposed the raw unit_ref id for every fact. For non-USD filers that id is an opaque token like UNIT_STANDARD_HKD_MNUS... instead of a usable currency, making currency-based filtering and display unreliable for foreign companies. Resolve each fact's unit to its ISO 4217 code (via the parsed iso4217: measure already available in xbrl.units) and expose it in a new 'currency' column. The raw unit_ref is preserved; per-share monetary units report their numerator currency; non-monetary units (shares, pure, custom) resolve to None rather than a misleading value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves #850.
xbrl().facts.to_dataframe()exposed the raw XBRLunit_refid for every fact. For non-USD filers that id is an opaque token such asUNIT_STANDARD_HKD_MNUSOXGRF0O9R60JINVDUQinstead of a usable currency, which made currency-based filtering and display unreliable for foreign companies (reported by @warzoo).What changed
The facts DataFrame now carries a
currencycolumn with each fact's ISO 4217 code (e.g.USD,HKD), resolved from the unit'siso4217:measure that the parser already records inxbrl.units. The opaqueunit_refis preserved unchanged —currencyis purely additive:iso4217:USD/xbrli:shares) report their numerator currency (USD).Nonerather than a misleading value.Verification
tests/issues/regression/test_issue_850.py:UNIT_STANDARD_HKD_...id resolves tocurrency == "HKD"whileunit_refstays opaque.usdPerShare) to"USD".currencyofNone, not a fabricated code.All three are red without the change. The existing facts/unit suites (
test_xbrl_unit_pointintime.py,test_xbrl_facts.py, …) show no new failures (the remaining failures are pre-existing network-dependent tests).ruff check/formatclean on the changed code.