Skip to content

Python: lookup_muni accepts 6-digit municipality codes (#444) - #460

Open
ArthurFachel wants to merge 1 commit into
ipea:masterfrom
ArthurFachel:feat/lookup-muni-6-digit
Open

ArthurFachel wants to merge 1 commit into
ipea:masterfrom
ArthurFachel:feat/lookup-muni-6-digit

Conversation

@ArthurFachel

Copy link
Copy Markdown

Closes #444 for the Python package. I don't have R set up, so the R side is untouched.

lookup_muni(code_muni=...) now accepts the 6-digit code without the IBGE check digit, which is what DATASUS systems (SIM, SIH, SINASC) store. With the 2010 municipal seats, all 5,565 codes have 7 digits and no 6-digit prefix repeats, so a 6-digit code maps to exactly one municipality.

Historical years are different. Their codes are synthetic (e.g. 1599902, 1599903 in 1872) and have no check digit, so prefixes repeat: 41 collisions in 1872 and 4 in 1940. When a 6-digit code matches more than one row, the function raises an error asking for the 7-digit code instead of returning several municipalities.

Other details:

  • Integral floats such as 3304557.0 still work, as they did with int(code_muni).
  • Malformed codes (wrong length, non-digits) raise the existing "valid municipality code" error instead of a bare int() ValueError.
  • CHANGELOG entry added under 2.1.2 (unreleased).

Tests: 11 new cases in tests/test_lookup_muni.py (20 pass). Full suite with -m "not network": 330 passed. Also checked against the real data: 431490 returns Porto Alegre for 2010 and 1991, and 159990 in 1872 raises the ambiguity error (4 matches).

@ArthurFachel

Copy link
Copy Markdown
Author

Oi @rafapereirabr, passando só pra lembrar deste PR também (junto com o #459). Se quiserem que eu mude algo no tratamento dos códigos de 6 dígitos, é só avisar.

@rafapereirabr

Copy link
Copy Markdown
Contributor

oi @ArthurFachel , obrigado pelo PR. Vou avaliar o PR com calma nas próximas semanas. Estamos com outras demandas mais urgentes mas vejo isso assim que der.

This branch has not been deployed

No deployments
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.

lookup_muni could receive 6-digit code of municipalities

2 participants