Overview
Fabric Pandas Migrator is a review-first codemod for bulk-migrating Python code that uses pandas toward PySpark workloads in Microsoft Fabric. Pandas and PySpark have genuinely different execution models — schemas, index semantics, ordering, Python UDFs and credentials cannot be inferred safely by any automated tool. This project is explicit about that: it discovers every .py file, detects pandas usage, copies the repository to a separate output directory by default, applies deterministic conversions, injects a Fabric Spark bootstrap where needed, and emits JSON, CSV and Markdown reports that flag what still needs human review.
It exists because "just rewrite it in Spark" migrations stall on exactly the code that looks easiest to translate. A review-first tool keeps the transformation honest: the boring 80% is automated, the risky 20% is surfaced with evidence, and CI can fail the build until review findings are resolved.
It is built for data engineers and analytics teams moving pandas batch jobs, notebooks and ETL into Microsoft Fabric, and for platform teams who need a repeatable, auditable migration pipeline rather than a one-off rewrite.
Use Cases
- Warehouse modernisation — move a legacy pandas ETL estate onto Fabric Lakehouse/Spark without a big-bang rewrite.
- First-pass API swap — flip
import pandas as pd to import pyspark.pandas as pd and keep pandas-shaped code running on Spark.
- Native PySpark rewrite — convert
read_csv/read_parquet/read_json/to_*/head/shape to native DataFrame calls with one deterministic pass.
- Pre-migration audit — run
scan alone to inventory pandas usage and risky patterns before committing to a timeline.
- CI-gated migration —
check --fail-on-review blocks merges until every REVIEW finding is resolved.
- Notebook-to-job conversion — export migrated modules, upload as notebook resources or build a wheel for a Fabric Environment.
- Risk discovery — surface
.apply(axis=1), .iterrows(), .iloc/.loc, Excel I/O, SQL connections and plotting code before they break in Spark.
- Dry-run rehearsal — preview every change with
--dry-run and share reports with stakeholders.
A Migration Sprint, Week One
Monday: the team lead runs fabric-pandas-migrate scan ./legacy-etl and pastes MIGRATION_REPORT.md into the planning doc — 140 files, 60 with pandas, 18 flagged for review. Tuesday: migrate --mode pandas-api produces a side-by-side copy in ./fabric-etl; nothing in the source tree is touched. They diff, run the unit tests against the Spark runtime, and fix the three unsupported APIs the report flagged. Thursday: a second pass with --mode native rewrites the I/O boundary to spark.read/write. Friday: check --fail-on-review goes into the pipeline; the remaining six findings get real tickets. The migrated code deploys to a Fabric notebook attached to a Lakehouse, validated against the pandas baseline on row counts, schemas, null counts and business aggregates — and every REVIEW item is closed before production scheduling.
Features
- Eight-step pipeline — discover
.py files, detect pandas, copy to a separate output directory, apply deterministic conversions, add a Fabric Spark bootstrap where needed, emit JSON/CSV/Markdown reports, flag unsupported patterns, optionally fail CI.
- Two migration modes —
pandas-api (recommended first pass) and native (see below).
- LibCST formatting — generated code stays parseable and formatted; the tool never executes your source files.
- Honest risk reporting — dynamic imports, non-
pd aliases, .apply(axis=1), .iterrows(), .iloc/.loc, Excel I/O, SQL connections, plotting and index-heavy logic are all reported for review.
- CI integration — exit codes:
0 success, 1 operational error, 2 unresolved review findings with --fail-on-review.
- Fabric-ready output — migrated modules plus
migration-report.json, migration-report.csv and MIGRATION_REPORT.md at the output root.
Migration Modes
pandas-api (recommended first pass): changes import pandas as pd to import pyspark.pandas as pd. It preserves most of the pandas-shaped API while moving execution to Spark — the quickest route for compatible analytics code. Unsupported APIs and index semantics still require validation.
native: converts a conservative, well-defined set of patterns to native PySpark DataFrame code:
pd.read_csv(path, ...) -> spark.read.options(...).csv(path)
pd.read_parquet(path) -> spark.read.parquet(path)
pd.read_json(path, ...) -> spark.read.options(...).json(path)
df.to_parquet(path, index=False) -> df.write.mode("overwrite").parquet(path)
df.to_csv(path, index=False) -> df.write.mode("overwrite").option("header", True).csv(path)
df.head(n) -> df.limit(n)
df.shape -> (df.count(), len(df.columns))
Everything else is retained and reported for review — by design.
Installation
The tool is a Python package installed with pip. A virtual environment is strongly recommended:
git clone https://github.com/PeaBox-Lab/Fabric-Pandas-Migrator.git
cd Fabric-Pandas-Migrator
python -m venv .venv
# Windows: .venv\Scripts\activate
# Linux/macOS: source .venv/bin/activate
pip install -e .
Python 3 with pip is required; the CLI entry point is fabric-pandas-migrate.
Quickstart — 30 Seconds
fabric-pandas-migrate scan ./legacy-app
fabric-pandas-migrate migrate ./legacy-app --output ./fabric-app --mode native
fabric-pandas-migrate check ./fabric-app --fail-on-review
Dry run first if you want to preview: fabric-pandas-migrate migrate ./legacy-app --output ./fabric-app --mode native --dry-run. In-place migration requires an explicit flag and creates .bak files: fabric-pandas-migrate migrate ./legacy-app --mode pandas-api --in-place.
Configuration & CI
There are no environment variables; behaviour is driven by CLI flags: --mode pandas-api|native, --output DIR, --dry-run, --in-place, --fail-on-review. Reports land in the output root. For CI, adapt the included GitHub Actions workflow to point at your application folder and gate on:
fabric-pandas-migrate check ./fabric-app --fail-on-review
# exit 0 = clean, exit 2 = unresolved REVIEW findings
Baseline exit-code contract: 0 success · 1 operational error · 2 review findings remain.
Microsoft Fabric Deployment
- Create a Fabric Lakehouse and a Notebook or Spark Job Definition; attach the Lakehouse.
- Upload migrated modules as notebook resources, or build a wheel (
python -m build) and add it to a Fabric Environment. - Prefer OneLake/Lakehouse paths and Delta tables over local paths.
- Run the migrated workload against representative data.
- Compare row counts, schemas, null counts, aggregates and business outputs against the pandas baseline.
- Resolve every
REVIEW item before production scheduling. See docs/FABRIC_DEPLOYMENT.md and docs/RULES.md.
Safety
- Default behavior never overwrites the source tree — output goes to a separate directory.
- Generated code is formatted by LibCST and remains parseable.
- The tool never executes source files.
- In-place mode requires an explicit flag and writes
.bak backups. - Unsupported patterns are reported, never silently guessed.
Troubleshooting
- Migration reports "unsupported pattern" everywhere — you're likely on
native mode with index-heavy code; try --mode pandas-api as the first pass.
--fail-on-review exits 2 in CI — open MIGRATION_REPORT.md (or .csv/.json) and resolve or ticket each finding; the gate is working as intended.
- Output differs from source intent — conversions are deterministic, not semantic; review the diff, especially around
index=False writes, head semantics and shape.
pyspark.pandas import fails in Fabric — ensure the Spark runtime includes the pandas API on Spark (standard in Fabric) and the notebook is attached to a Lakehouse.
- Non-
pd alias not converted — only common aliases are rewritten; rename your import alias or expect a review finding.
- In-place run scared you — restore from the
.bak files the tool created alongside each modified file.
Release & License
MIT licensed (see LICENSE). This is an early-stage, actively developed tool: the conversion ruleset is deliberately conservative, and anything ambiguous is reported rather than guessed. Contributions welcome — see docs/RULES.md for the rule catalog.
github.com/PeaBox-Lab/Fabric-Pandas-Migrator · PeaBox Lab help & docs