Skip to content

Migration 0.2.0: PyArrow and ingestion integrity

Version 0.2.0 moves production ingestion paths to PyArrow, removes Polars
from library dependencies, and strengthens CVM and B3 integrity guarantees. The
three root public facades and their signatures remain stable:

from globaldatafinance import (
    ExtractionResultB3,
    FundamentalStocksDataCVM,
    HistoricalQuotesB3,
)

Consumer-facing changes

Change Required action
Strict B3 parser Correct the source file or handle ExtractionError; invalid values no longer fall back to zero, an empty string, or null.
Polars removed Install Polars explicitly if the application uses it to read Parquet.
ExtractorAdapter.extract_csv_from_zip_to_parquet removed Migrate internal use to the CVM facade or another appropriate public interface.
Pandas metadata removed Do not depend on physical b'pandas' metadata; use logical schemas and values.
Fully filtered B3 input Treat an empty Parquet as a valid result when TPMERC filtering finds no assets.
Canonical archive namespace Use Settings.archive; Settings.archive_safety no longer exists and has no compatibility alias.
Strict logging configuration Use only documented LoggingSettings fields and environment variables; LoggingSettings(structured=True) and unknown DATAFIN_LOG_* variables now raise ValidationError.
Logging destination and context Use a log_file under an application-approved directory; roots/protected directories are rejected, and common secret fields receive best-effort redaction. Do not send secrets to logging.
Exact CVM preservation Regenerate Parquets as exact-text-v1; all columns are strings and numeric conversions are explicit.
B3 internal clean cut Remove data_writer from integrations constructing ExtractionServiceB3 and do not pass resource_monitor to ParquetWriterB3; use the current facades and signatures.
Reserved B3 sentinel The literal __GLOBALDATAFINANCE_NULL__ is not accepted as a value; use None for nulls.

CVM

The current CVM contract is exact-text-v1: string columns, empty fields as
"", original values preserved, and ZIP retention after extraction.
QUOTE_NONE keeps literal quotes and short rows receive trailing empty fields.
Multi-Parquet publication remains recoverable as a batch, with all records
verified before promotion. See the CVM exact text migration
for regeneration, explicit conversions, and lock inspection after interruption.

Library logging does not alter the application root logger. Before an explicit
setup_logging() call, the globaldatafinance namespace uses a NullHandler
and remains quiet; a handler reconfiguration failure preserves the previous
configuration.

Notes for release 0.2.0

These notes summarize what changes when upgrading from 0.1.4 to 0.2.0.

Breaking changes when upgrading from 0.1.4:

  • CVM: all Parquet columns become Arrow string, with empty fields as
    "" and preserved leading zeros and decimal text. Regenerate files from
    their ZIP sources; consumers must explicitly convert numeric columns. See
    the CVM text migration.
  • Dependencies: Pandas and Polars are no longer installed or imported by
    the runtime. Install them explicitly if your application uses DataFrames.
  • Removed imports: globaldatafinance.__version__, ExtractorAdapter,
    ReadFilesAdapter, and the generic
    macro_infra.extractor_file/macro_infra.read_files modules are removed.
    Read the version with importlib.metadata.version("globaldatafinance")
    and migrate adapters to the source-owned components.
  • Timeout: replace imports of the domain TimeoutError exception with
    DownloadTimeoutError; Python’s built-in exception is distinct. See the
    infrastructure guide for these
    removals and the changed write-error behavior.
  • B3 fast: eligible multi-source runs now default to spawn processes.
    Protect script execution with if __name__ == '__main__':, or set
    GDF_B3_EXECUTOR_BACKEND=thread before constructing the facade to retain
    threads as in 0.1.4. Calls during child bootstrap now fail before source
    revalidation; the pool error explains the correction. Put CVM downloads
    and other application side effects inside the main guard too: the library
    cannot prevent code that executes before the B3 call.
  • Persisted B3 data: migrate market selection and regenerate Parquets
    with schema v2 as described below. Read this release’s migration guides
    together before updating consumers.

Dependency requirements:

  • PyArrow: >=26.0.0,<27.0.0.
  • psutil: >=7.2.2,<8.0.0.
  • pydantic-settings: >=2.16.2,<3.0.0.

The development lock also updates virtualenv to 21.14.13, fixing
GHSA-cx6f-vjhg-g3cc
in Bash environment activation. This dependency is used by pre-commit.

Breaking COTAHIST contract changes:

  • The default selection now preserves every type-01 quotation, including
    TPMERC 021 and unknown numeric markets. Omit assets_list or use todos;
    specify classes when a consumer requires a filter.
  • Parquet moves to versioned schema 2 with 32 columns. The original 20 fields
    retain their order and values; the 12 additions include the omitted official
    fields, provenance, and the original 245 quotation bytes.
  • Regenerate v1 Parquets from the original ZIP/TXT sources. Append and merge
    across incompatible schemas fail; converting v1 files cannot recover missing
    data. Follow the cutover and rollback procedures on this page.
  • Specify an available annual range: any missing requested year or invalid
    record fails extraction, including a record in a filtered-out market.
  • Publication requires complete staged-output readback and exact data and
    manifest verification. Failures preserve the previous output; consumers must
    check success, schema_version, and integrity before switching files.

The local acceptance corpus covers 2000–2026, with a snapshot ending on
2026-09-02. The checksum manifest and the campaign evidence are versioned with
the corpus audit. These
bounds are not independent confirmation of exchange coverage or availability of
every historical year.
A supplementary 2025–2026 acceptance
verified 6,604,374 quotations through 2026-11-06 with exact fast/slow
equality, using the Latin-1 copy explicitly recorded below.

Official 2026 source and disk space: a November version of
COTAHIST_A2026.ZIP contains one UTF-8 record occupying 246 bytes instead of
the required 245. Strict validation rejects that file and preserves the
previous output. Retain the original and follow the
explicit conversion to a Latin-1 copy;
the extraction hashes and registro_original identify that converted copy.
The free-space rule conservatively
estimates staging and publication needs and can substantially exceed the
final Parquet size.

Restart after a crash: new transaction locks also record the process
start time for diagnostics. This timestamp can change with clock adjustments,
so a live PID with a different start time cannot authorize recovery.
Automatic recovery requires the recorded PID to no longer exist on the same
host and process namespace; live PIDs, including reused ones, and locks from
another host require inspection.
Follow the manual CVM/B3 recovery procedure.

Windows console: redirected Windows output, such as > log.txt,
scheduled tasks, or subprocesses, commonly uses a legacy code page. CVM and B3
progress and summaries no longer abort with UnicodeEncodeError there: bars
use # and -, and unsupported symbols become ?. The 0.1.4 release had
this failure.

B3

Every 01 record is validated and converted before market selection. Blank
lines and 00/99 controls are counted, while every other nonempty identifier
fails. Both modes use canonical conversion and bounded CSV row batches through
Arrow. fast uses batches of up to 25,000 records and can process sources in
parallel; slow uses batches of up to 10,000 records and one worker. Both
preserve the same logical schema, order, and values.

B3 schema v2 and regeneration

The persisted COTAHIST contract changed incompatibly to versioned schema 2.
The default is now assets_list=None, equivalent to assets_list=["todos"]:
all type-01 quotations with numeric TPMERC codes are preserved, including
021 and codes that are not yet known. The output has 32 columns, adding the
five previously omitted official fields, source coordinates, and the original
245 bytes of each quote. Financial values use exact decimals;
preco_exercicio_pontos has scale 6.

Version 1 Parquets do not contain TPMERC 021 rows, all official fields, or
original source bytes. Do not convert or append these files into v2. Regenerate
from the raw ZIP/TXT sources and validate the output before switching consumers.

Cutover procedure:

  1. Preserve the COTAHIST sources and record their hashes.
  2. Choose the annual range actually available. Pass initial_year and
    last_year; defaults still cover 1986 through the current year, and any gap
    inside the requested range fails extraction.
  3. Write to a separate destination using assets_list=["todos"] (or omit
    assets_list).
  4. Require result["success"] is True and result["schema_version"] == 2.
    Review selection_complete, source_complete, counts, selected years, and
    output_sha256 in result["integrity"] for the consumer’s requirements.
  5. Read the Arrow schema and adapt consumers to the 12 added columns and exact
    types in the B3 v2 schema reference.
  6. Switch consumers to the verified output and retain v1 files until the
    cutover is accepted.

Rollback procedure:

  1. Keep the previous package version, consumer configuration, and v1 Parquet
    paths together until accepting the migration. Record the SHA-256 of each
    previous output and generate v2 in a separate directory.
  2. If acceptance fails, restore the previous package version and consumer
    configuration to read the retained v1 paths. Leave the original COTAHIST and
    separate v2 artifacts available for diagnosis.
  3. Verify the retained v1 checksums and reopen them with the previous consumer.
    Do not overwrite v2 with v1 or append rows between schema versions.

The library publishes one caller-selected output; changing the consumer’s
chosen path belongs to the application. A failed extraction preserves the
previous file at that output path and returns output_file="". These guarantees
are exercised by tests/application/b3_docs/test_publication_integrity.py and
tests/application/b3_docs/test_schema_migration.py.

A filtered v2 Parquet may contain zero rows and still be complete for the
requested selection; review selection_complete, source_complete, and
intentional-exclusion counts. source_complete=True requires zero exclusions.
Reports include outer and uncompressed-content hashes, Base64 controls, trailer
convention, observed dates, row digest, and final Parquet hash. These facts
attest the supplied files; they do not confirm a trading calendar or instruments
outside the corpus. Years before 2000 require separate source files and are not
included in the locally audited corpus.

Integrations that depended on removed internal objects must migrate to the
facade flow. The B3 session now has an explicit lifecycle (NEW → OPEN →
CLOSED) and cannot be reopened after closing, including when final
validation fails.

Internal workers use only the canonical CotahistParserB3 conversion, including
source replay and digest verification for subclasses. Custom factories that
provided only parse_line() must implement the complete parser contract; the
alternative dictionary path was removed. The internal normalize_decimal_v99
helper and unused ZipProcessingResult/ProcessSingleFileResult types were
removed. Use normalize_decimal with an explicit scale in internal extensions.

Text-reading interfaces and ParquetWriterB3 with existing callers remain
available over the current implementation. Module documentation lives in
README.md and README.en.md; the stale README.pt.md copy was removed.

In this migration to 0.2.0, the following five historical names are retained
to preserve existing integrations in their current internal namespaces:

Name Status in this migration
CotahistParserB3.EXPECTED_LINE_LENGTH Historical record-width attribute derived from the canonical 245-byte layout.
extraction_service.types.ParsedRecord Typing alias retained for existing imports.
extraction_service.types.ExtractionSummary Historical type retained for existing imports; it does not define the complete public result.
ExtractHistoricalQuotesUseCaseB3.execute_sync Synchronous entrypoint retained over the current asynchronous implementation.
CreateSetToDownloadUseCaseB3 File discovery retained over current path and source validation.

New integrations should use HistoricalQuotesB3 and the public
ExtractionResultB3 contract. Retaining these names in this migration does not
expand root exports.

Dependencies and measurement

ReadFilesAdapter was removed together with the automatic Pandas dependency;
consumers who still want DataFrames must install Pandas themselves. PyArrow is
the only production CSV/Parquet engine. Use
scripts/benchmark_ingestion.py for local fresh-process measurements; its
numbers depend on hardware, environment, and corpus, so they are not universal
time or RSS guarantees. The complete timeout, generic adapter, B3 catch-boundary,
and write-failure migration is documented in Infrastructure clean cut.