Skip to content

feat(reference): map EDGAR place codes to ISO 3166-1 alpha-2 country codes - #1496

Merged
dgunning merged 3 commits into
dgunning:mainfrom
shahar-arbor:place-code-iso-country
Oct 8, 2026
Merged

dgunning merged 3 commits into
dgunning:mainfrom
shahar-arbor:place-code-iso-country

Conversation

@shahar-arbor

@shahar-arbor shahar-arbor commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Before: place_codes.csv gave a place code's name and type, but not its country code. So E9 could not be joined to data keyed on KY.

After: get_place_country_code(code) returns the ISO 3166-1 alpha-2 country code. It reads a new ISO column in place_codes.csv.

  • US states → US.
  • US territories keep their own ISO code: PR, GU, VI, AS, MP, UM.
  • Canadian provinces → CA.
  • P8 (Netherlands Antilles) → the withdrawn code AN.
  • XX (unknown) → None.

_load_place_codes() now passes keep_default_na=False. Without it, pandas reads Namibia's ISO code NA as missing.

Fixes #1495

Verification

  • Ground truth: Accelerant Holdings (CIK 1997350). Its submissions JSON gives addresses.business.stateOrCountry = "E9" with description "Cayman Islands", and get_place_country_code("E9") == "KY". Every foreign row was checked against the pycountry name for its code. Only spelling variants differ ("TURKEY"/"Türkiye", "SWAZILAND"/"Eswatini").
  • Silence check: get_place_country_code("ZZ") returns None, to match get_place_name() and get_place_type() for an unknown code. If you prefer a raise for codes not in the table, I can change it.
  • Docs: docs/guides/reference-data.md lists the function. Its examples run. I also corrected one existing example: get_place_name("A6") returns "Ontario Canada", not "Alberta, Canada".
  • Changelog: changelog.d/1495.added.md. assemble_changelog.py --check passes.

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 NA trap showed up when the CSV was read back: 2 NaNs, Namibia and XX.

🤖 Generated with Claude Code

shahar-arbor and others added 2 commits October 8, 2026 10:19
…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>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dgunning
dgunning merged commit a6d94a4 into dgunning:main Oct 8, 2026
11 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.

Reference: map EDGAR place codes to ISO 3166-1 alpha-2 country codes

2 participants