Repository navigation
fix(dbf): detect the text encoding from the DBF header - #389
Merged
Merged
Conversation
The fast DBF reader decoded every file as latin-1, but SIH files declare cp850 in the header (LDID, byte 29), so ç (0x87) came out as U+0087. - read_dbf_fast, read_dbf_filtered and stream_dbf_fast take encoding=None by default and use the code page declared by the LDID; LDID 0x00 and unknown LDIDs (0x35 in SIM) use fallback_encoding (latin-1). Passing encoding= still overrides detection. - Decoding is lossless for single-byte code pages: a byte the code page leaves undefined (0x81 in cp1252) maps to the code point with the same number, as the WHATWG windows-1252 decoder does. - The encoding is passed down to _decode/_decode_column instead of being written to the module-level _ENCODING, so concurrent reads of files with different code pages no longer overwrite each other. - The dbfread path in DBF.load/stream/to_parquet (fast=False, or the fallback when the fast reader fails) used a fixed cp1252; it now uses the same detected encoding, exposed as DBF.encoding. Refs AlertaDengue#382
davispecia
force-pushed
the
fix/dbf-encoding-from-ldid
branch
from
November 21, 2026 16:45
b32617f to
313faba
Compare
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #389 +/- ##
=======================================
Coverage ? 97.37%
=======================================
Files ? 185
Lines ? 24442
Branches ? 0
=======================================
Hits ? 23800
Misses ? 642
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
luabida
approved these changes
Nov 23, 2026
|
🎉 This PR is included in version 2.12.3 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
luabida
added a commit
to luabida/PySUS
that referenced
this pull request
Nov 23, 2026
Add --group filtering to management check/run, applied to both origins and S3 mirrors, and a --reupload-encoding shortcut for the SIA/SIH groups affected by the DBF encoding fix (AlertaDengue#389). The shortcut selects SIA AD/AN/AR/BI and SIH RD/RJ, implies --force, and uses a stable journal so an interrupted run resumes where it stopped. Dry runs with --force preview every selected file as outdated. Add pysus.management.scripts.reupload_encoding as a standalone resumable job with --status, --reset and --dry-run. It checkpoints the catalog on interrupt before exiting so uploaded files are not missing from the catalog on restart.
luabida
added a commit
to luabida/PySUS
that referenced
this pull request
Nov 23, 2026
Add --group filtering to management check/run, applied to both origins and S3 mirrors, and a --reupload-encoding shortcut for the SIA/SIH groups affected by the DBF encoding fix (AlertaDengue#389). The shortcut selects SIA AD/AN/AR/BI and SIH RD/RJ, implies --force, and uses a stable journal so an interrupted run resumes where it stopped. Dry runs with --force preview every selected file as outdated. Add pysus.management.scripts.reupload_encoding as a standalone resumable job with --status, --reset and --dry-run. It checkpoints the catalog on interrupt before exiting so uploaded files are not missing from the catalog on restart.
luabida
added a commit
to luabida/PySUS
that referenced
this pull request
Nov 23, 2026
Add --group filtering to management check/run, applied to both origins and S3 mirrors, and a --reupload-encoding shortcut for the SIA/SIH groups affected by the DBF encoding fix (AlertaDengue#389). The shortcut selects SIA AD/AN/AR/BI and SIH RD/RJ, implies --force, and uses a stable journal so an interrupted run resumes where it stopped. Dry runs with --force preview every selected file as outdated. Add pysus.management.scripts.reupload_encoding as a standalone resumable job with --status, --reset and --dry-run. It checkpoints the catalog on interrupt before exiting so uploaded files are not missing from the catalog on restart.
luabida
added a commit
to luabida/PySUS
that referenced
this pull request
Nov 23, 2026
Add --group filtering to management check/run, applied to both origins and S3 mirrors, and a --reupload-encoding shortcut for the SIA/SIH groups affected by the DBF encoding fix (AlertaDengue#389). The shortcut selects SIA AD/AN/AR/BI and SIH RD/RJ, implies --force, and uses a stable journal so an interrupted run resumes where it stopped. Dry runs with --force preview every selected file as outdated. Add pysus.management.scripts.reupload_encoding as a standalone resumable job with --status, --reset and --dry-run. It checkpoints the catalog on interrupt before exiting so uploaded files are not missing from the catalog on restart.
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.
Closes #382
O leitor rápido de DBF decodificava tudo como latin-1, mas os arquivos do SIH declaram cp850 no cabeçalho, então o
çvirava U+0087.O que muda:
0x00ou desconhecido (como o0x35do SIM) cai em latin-1, que é o comportamento atual.encoding=continua forçando um code page, efallback_encoding=muda o padrão.0x81em cp1252) vira o code point de mesmo número, então o valor original pode ser recuperado.dbfread(fast=Falseou fallback) usava cp1252 fixo. Agora usa o mesmo encoding detectado (DBF.encoding).Testes com cabeçalhos sintéticos (cp850, cp1252, LDID desconhecido) nos três leitores rápidos e no caminho do dbfread, além de leitura concorrente. A suíte completa passa localmente.
Os parquets do SIH já convertidos ficaram com o texto errado, então vale reconverter esses arquivos.