Overview
License: Apache-2.0 · GitHub: mohamedhossammohamed · X: @MohamedHz72007
This directory contains the organized technical documentation for the high-performance Pandas categorical mutation native extension project. The current implementation bridges Python with a Zig shared library through a strict C ABI to remap contiguous categorical code buffers without expanding labels into object arrays.
Documentation Index
| # | Document | Focus Area |
|---|---|---|
| 1 | 01-categorical-internals-and-memory.md | Pandas categorical internals, memory layout, and the object-mode fallback bottleneck |
| 2 | 02-ffi-zero-copy-architecture.md | FFI boundary design, C-ABI safety, buffer protocol, and zero-copy mutation mechanics |
| 3 | 03-performance-algorithms.md | Performance strategies, CPU cache locality, SIMD options, and lookup table tradeoffs |
| 4 | 04-build-systems-and-distribution.md | Build systems, CI/CD pipelines, cross-platform wheel distribution, and dynamic loading |
| 5 | publishing.md | PyPI release workflow, trusted publishing setup, and install verification |
| 6 | ../CHANGELOG.md | Version history, API changes, and native ABI changes |
Architecture Overview
The system is designed for relabeling categorical columns where the category metadata is small but the integer codes buffer is large. The goal is to avoid expanding a full column into object arrays or building large temporary masks.
Core Architectural Layers
- Data Layer — Pandas Categorical internals and NumPy-backed integer codes
- Boundary Layer — Foreign Function Interface (FFI) via C-ABI with borrowed pointer handoff
- Compute Layer — Native scalar LUT remapping in Zig with explicit validation reports
- Packaging Layer — PEP 517 build hooks, cibuildwheel CI matrices, and platform wheels
- Runtime Layer — Dynamic library loading, Python-owned buffer safety, and validated Pandas reintegration
Key Design Principles
- Zero-Copy In-Place Path: Pass raw memory pointers across the FFI boundary without serialization
- GIL Bypass: Release the Python Global Interpreter Lock during native execution to maximize throughput
- Memory Safety: Keep Python as the owner of all buffers and expire native borrowed pointers on return
- CoW Compliance: Prefer public Pandas APIs and explicit copy semantics for high-level remaps
- Frictionless Distribution: Pre-compile wheels for Linux, macOS, and Windows via GitHub Actions + cibuildwheel
Reading Order
For engineers new to the codebase, the recommended reading order is:
- 01-categorical-internals-and-memory.md — Understand *why* the problem exists
- 02-ffi-zero-copy-architecture.md — Understand *how* we cross the language boundary safely
- 03-performance-algorithms.md — Understand *how* we maximize CPU throughput
- 04-build-systems-and-distribution.md — Understand *how* we package and ship the native binaries
- publishing.md — Understand *how* to publish and verify the package
- CHANGELOG.md — Understand *what changed* between releases