Repository navigation
feat(reference): map EDGAR place codes to ISO 3166-1 alpha-2 country codes - #1496
Merged
Merged
Conversation
…codes (dgunning#1495) place_codes.csv gains an ISO column and _codes.py a get_place_country_code() beside get_place_name()/get_place_type(). US territories keep their own ISO code; Netherlands Antilles keeps the withdrawn AN; XX (unknown) is None. The loader now passes keep_default_na=False: pandas otherwise reads Namibia's ISO code "NA" as a missing value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 tasks done
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What this changes
Before:
place_codes.csvgave a place code's name and type, but not its country code. SoE9could not be joined to data keyed onKY.After:
get_place_country_code(code)returns the ISO 3166-1 alpha-2 country code. It reads a newISOcolumn inplace_codes.csv.US.PR,GU,VI,AS,MP,UM.CA.P8(Netherlands Antilles) → the withdrawn codeAN.XX(unknown) →None._load_place_codes()now passeskeep_default_na=False. Without it, pandas reads Namibia's ISO codeNAas missing.Fixes #1495
Verification
addresses.business.stateOrCountry = "E9"with description "Cayman Islands", andget_place_country_code("E9") == "KY". Every foreign row was checked against thepycountryname for its code. Only spelling variants differ ("TURKEY"/"Türkiye", "SWAZILAND"/"Eswatini").get_place_country_code("ZZ")returnsNone, to matchget_place_name()andget_place_type()for an unknown code. If you prefer a raise for codes not in the table, I can change it.docs/guides/reference-data.mdlists the function. Its examples run. I also corrected one existing example:get_place_name("A6")returns "Ontario Canada", not "Alberta, Canada".changelog.d/1495.added.md.assemble_changelog.py --checkpasses.Also run:
pytest tests/reference/test_reference.py -k place: passes, offline.ruff check edgar: same count as main.check_regression_provenance.py: OK.I kept the surrounding quote style and did not run
ruff format, because it would rewrite unrelated lines in both files.6.0
Not a 6.0 change.
Working context (optional)
I wrote this with Claude Code, starting from the 308-code map we keep in our own SEC IPO parser. That map is now this column. The
NAtrap showed up when the CSV was read back: 2 NaNs, Namibia andXX.🤖 Generated with Claude Code