Why pandas/Polars/PyArrow don’t run в browser
Студент может удивиться: “Платформа на Pyodide; почему pandas / Polars / PyArrow преподаются conceptually + Run-on-Your-Machine, а не интерактивно как stdlib challenges?” Этот урок объясняет constraint + decision: WASM size limits + C/Rust extension dependencies + micropip experimental status делают full library bundling непрактичным в course-scope. Pure-stdlib challenges (Pattern 4) + Run-on-Your-Machine для real demos — pragmatic compromise.
В этом уроке:
- Why this lesson exists — pedagogical контекст.
- WASM size constraints — pandas (~50MB), Polars (~30MB), PyArrow (~50MB).
- C/Rust extension dependencies — pandas → NumPy → 30+ C extensions.
- micropip experimental status —
micropip.install(...)works for some, not all. - What runs в Pyodide today — pure-stdlib + NumPy partial.
- Decision: switch к local Python execution — Run-on-Your-Machine recap.
- Cross-link M00 урок 03 — Pyodide environment foundation.
Why this lesson exists
Учащиеся приходят в M10 с ожиданиями interactive pandas REPL (как в Jupyter / Colab). Платформа использует Pyodide — браузерный CPython (3.12.x, compiled к WASM). pandas / Polars / PyArrow существуют для Pyodide через micropip — но их использование в course-context имеет несколько барьеров. Этот урок документирует решение учить conceptually + Run-on-Your-Machine для real-engagement.
WASM size constraints
| Library | Approx WASM bundle size | Reason |
|---|---|---|
| pandas (with deps) | ~50MB | NumPy + Cython + 30+ C extensions |
| Polars | ~30MB | Rust binary + minimal deps |
| PyArrow | ~50MB | C++/Rust Arrow core + parquet + ipc + compute kernels |
| NumPy alone | ~10MB | C/Fortran linear algebra |
Сравнение: наш platform Pyodide bundle (/python-course/<lesson> page) — ~5MB Python runtime + lesson MDX (~20-50KB). Загрузка pandas в browser добавляет 50MB к page load — 10x increase. На mobile / slow connections это блокирует initial render.
Trade-off: инструктор может ждать загрузки 50MB ради Jupyter-like experience? Course-design says no для broad accessibility — keep page load fast (~5MB) → Pyodide stdlib challenges.
C/Rust extension dependencies
pandas зависит от:
pandas
├── numpy (C extensions: ndarray, ufunc, linalg)
├── python-dateutil
├── pytz
├── numexpr (optional, C++)
├── bottleneck (optional, C)
└── (множество других optional deps)
Pyodide compiles C extensions к WASM — но build complexity high. Каждое minor pandas / numpy update требует rebuild Pyodide WASM bundles. Pyodide project ships WASM bundles периодически, не sync с upstream. Production rule: assume Pyodide pandas lags upstream pandas by 6-12 months.
Polars — Rust binary; полная rebuild нужна для каждой Polars version. Pyodide Polars bundle exists для некоторых versions, не всех.
PyArrow — C++/Rust core; даже больше build complexity.
micropip experimental status
import micropip
await micropip.install('pandas') # downloads + installs WASM bundle
Это работает для libraries с pre-built Pyodide WASM bundles. Status (state of the art 2026):
- Tier 1 (works reliably):
numpy,pandas,scikit-learn,matplotlib,requests— Pyodide upstream maintains. - Tier 2 (experimental — may break version-to-version):
polars,pyarrow— depends на upstream contributors. - Tier 3 (unsupported): libraries с heavy C dependencies (e.g.,
tensorflow,pytorch,lxml).
Course constraint: production-stability important. Tier 2+ — too experimental для course content (versions меняются, learner может загружать lesson через год — micropip install fails). Pure-stdlib (Tier 0) — guaranteed available, stable across Pyodide versions.
Cite Pyodide FAQ — Loading packages + micropip docs.
What runs в Pyodide today (course assumption v2.4)
Pure-stdlib (always available, all versions):
io,csv,json,pathlib(M09 challenges Pattern 1/2/3)itertools,collections,statistics,functools,operator(M10 Pattern 4 challenges)dataclasses,enum,inspect,re,typinggzip,bz2,lzma(M09 урок 05 demos)unittest(Phase 67 M08 testing)
NumPy — partial available через pyodide.loadPackage('numpy') или await micropip.install('numpy') — opt-in load (~10MB extra). Pyodide upstream maintains. Course не требует NumPy для challenges (хотя могло бы).
Pandas / Polars / PyArrow — NOT bundled в course-scope. Available через micropip.install(...) но experimental status + load time не подходит для browser interactive challenges.
Decision: switch к local Python execution
Course strategy для М10 Data Libraries:
- Concept lessons (М10 уроки 01-04, 06) — prose + diagrams + cross-course links. Объясняем что и зачем, без runtime в browser.
- Pure-stdlib challenges (Pattern 4) —
itertools.groupby+statistics.mean≈ pandas groupby;Counter.most_common≈ pandas value_counts. Tests algorithm understanding. - Run-on-Your-Machine callouts (≥3 в М10 — уроки 01/02/03) —
pip install 'pandas>=2.2,<3.0'+ minimal demo + expected output. Tests library API engagement.
Pedagogical principle: library-specific runtime (pd.DataFrame(...), pl.scan_csv(...), pa.Table.from_pylist(...)) — local Python territory. Course taught browser-stdlib для accessibility; library mastery deferred к learner’s own venv (~5 min pip install).
Run-on-Your-Machine convention recap
Total Run-on-Your-Machine callouts через course (Phase 64 → Phase 68):
| Module | Count | Purpose |
|---|---|---|
| M00 урок 03 (pyodide-env) | 1 | First introduction — establishes convention |
| M07 урок 07 (mypy-bridge) | 1 | mypy local install |
| M08 (testing-pytest, 5 callouts) | 5 | pytest local install + actual test runs |
| M09 урок 06 (pathlib mandate) | 1 | real disk operations |
| M09 урок 07 (summary) | 1 | optional full pipeline |
| М10 уроки 01, 02, 03 (this phase) | 3 | pandas / Polars / PyArrow demos (mandatory per SC#6) |
| Cumulative course-wide | 12 | broad pedagogy для local-machine engagement |
Convention shape (Pattern 5) — ингредиенты <Callout type="tip"> блока:
- Заголовок — bold
**Run-on-Your-Machine: <library> <operation>**— convention starts с literal “Run-on-Your-Machine:” prefix (validate-run-on-your-machine.cjs gate в Wave 0). - Установка —
pip install '<library>>=<min>,<<max>'(Pitfall 32 — version pin always). - Файл-demo — fenced
pythoncode-block с realистичным API usage (rendered as syntax-highlighted text, NOT executed). - Команда run — fenced
bashcode-block, обычноpython3 <demo>.py. - Ожидаемый вывод — fenced text block с expected stdout.
- (Optional) — comparison к browser challenge stdlib equivalent (Pattern 4 link).
Реальные примеры — М10 уроки 01 (pandas), 02 (Polars), 03 (PyArrow) выше; М08 уроки 02, 03, 05 (pytest) — Phase 67 baseline.
Pitfall 32 (carrying от Phase 67) — always version-pin в pip install. Без pin — pip install pandas загружает latest, breaking changes возможны (e.g., pandas 3.0 — CoW default).
Cross-link M00 урок 03 — Pyodide environment foundation
M00 урок 03 pyodide-env — first encounter с constraints. Promised:
Browser execution = stdlib only. Library mastery → local venv (Run-on-Your-Machine convention to come).
М10 урок 05 (this) — implements promise + recaps decision rationale + bridges к Run-on-Your-Machine pattern.
Three-phase pedagogy:
- M00 урок 03 — promise (constraint introduced).
- M07/M08/M09 — Run-on-Your-Machine first occurrences (12 cumulative callouts shipped).
- M10 урок 05 — synthesis lesson (constraints documented + decision justified).
Что в следующем уроке
М10 урок 06 — Decision matrix — когда выбрать pandas / Polars / PyArrow / DuckDB / Spark / DataFusion. Factor matrix: data size / single-machine vs distributed / lazy API / Arrow interop / language ecosystem. Optional Pattern 4 variant py-m10-06-code-1 (top-K via Counter.most_common).