A lead must standardise how a team's pandas jobs hand DataFrames to each other on disk: which writer do you choose, and what does that choice cost?
answer
- what survives the round trip
- a dependency to pin
- index and column-name rules
- humans read at the edges
- shared mutable state lives elsewhere
basics
~20 sStandardise on to_parquet with the pyarrow engine and index=False for handoffs: it round-trips most pandas dtypes and supports column and filter pushdown. The cost is pinning PyArrow, enforcing string column names and no Python-object columns, and keeping CSV and Excel as edge exports.
solid answer
~40 sI compare writers by what pandas round-trips. `to_parquet` with the pyarrow engine keeps time-zone-aware datetimes, nullable integers, string types and string categoricals, and lets readers use `columns=` and `filters=`; in pandas 3.0 the default `str` text columns come back as `str`, while CSV re-infers every column on each read. So the standard is `to_parquet(engine='pyarrow', index=False)`, partitioned by the key readers filter on, with a declared `schema=`. The costs: PyArrow becomes a pinned dependency, column names must be strings, object columns of Python objects fail, non-string categoricals lose their category dtype, and non-pandas readers need the index kept out. Feather suits short-lived same-platform scratch; CSV and Excel are for people; shared mutable data goes to a database.
go deeper
Recall that to_parquet and read_parquet keep dtypes, while to_csv and read_csv re-infer them on every read.
Explain to_parquet's index default, the pyarrow and fastparquet engines, and which dtypes Parquet and Feather round-trip.
Name the failure modes a convention prevents: engine drift, object columns, extra index columns, non-string categoricals and schema drift between jobs.
Own the trade-off: one typed handoff format with pinned PyArrow and a declared schema, Feather for scratch, CSV and Excel at the edges, and a database for shared mutable state.
## The decision A team's pandas jobs pass DataFrames to each other through files: an extract job hands cleaned data to a feature job, which hands results to a reporting job. A lead has to set the convention, because every job that writes in its own way forces every reader to guess. The candidates pandas offers are `to_parquet`/`read_parquet`, `to_feather`/`read_feather`, `to_csv`/`read_csv`, `to_json`, `to_excel` and `to_sql`. There is no single right answer, but there is a right way to compare them: by **what pandas round-trips**, what each **costs to run**, and **who else reads** the files. ## What pandas round-trips | writer | dtypes on read-back | index | partial reads | notes | |---|---|---|---|---| | `to_parquet` (pyarrow) | numeric, bool, datetime with time zone, category with string categories, nullable `Int64`, string types, Period and Interval | default RangeIndex as metadata; others as columns | `columns=`, `filters=` | non-string categories come back as their plain dtype | | `to_feather` | the pandas dtypes, including category and time-zone-aware datetimes | documented as needing a default index; `reset_index()` first | `columns=` | Arrow IPC; fast, built for short-lived files | | `to_csv` | none: every read re-infers types | written as a column unless `index=False` | `usecols=` | human-readable, universally read | | `to_excel` | re-inferred per sheet | written unless `index=False` | `usecols=` | for people, not pipelines | | `to_sql` | the database's types | written unless `index=False` | a query | shared, concurrent, governed | Parquet's documented caveats in pandas are the ones to put in a team rule: - Duplicate column names and non-string column names are listed as unsupported, and index level names must be strings. - Columns of actual Python objects (an `object` column holding dicts or custom classes) raise an error at write time. - With the pyarrow engine, a `category` column with **non-string** categories reads back as its primitive dtype. - A non-range index becomes an extra column (`__index_level_0__`) that non-pandas readers do not expect. In pandas 3.0, text columns infer the `str` dtype, backed by PyArrow when it is installed. Parquet stores them as Arrow strings and `read_parquet` returns them as `str` again, while `to_csv` and `read_csv` re-infer every column each time. That makes the typed binary formats the natural carrier for 3.0 frames. ## What each choice costs the team 1. **A dependency to pin.** `to_parquet` with `engine='auto'` tries pyarrow, then fastparquet, and the two differ: fastparquet filters only at partition and row-group level, does not support `dtype_backend`, and lacks the Period and Interval types. Pin `engine="pyarrow"` and pin the PyArrow version alongside pandas. 2. **A schema to own.** `to_parquet` forwards a `schema=` keyword to PyArrow's table conversion, so a team can declare each dataset's schema once; a column that cannot be converted to it fails at write time instead of surprising the reader. 3. **Conventions to enforce:** `index=False` (or an explicit `reset_index()`), string column names, no object columns of Python objects, explicit `compression`. 4. **Readers outside pandas.** If a warehouse or another language reads the files, Parquet is the shared choice; Feather is best kept for fast, short-lived handoffs on the same platform. 5. **Humans at the edges.** CSV and Excel stay as **export formats** for people and partner systems, produced at the end of the pipeline, never as the handoff between two pandas jobs. 6. **When a file is the wrong answer.** Data that many processes update concurrently or query ad hoc belongs in a database through `to_sql`, at the cost of insert throughput. ## A defensible default - **Between jobs:** Parquet through `to_parquet(engine="pyarrow", index=False)`, partitioned by the key readers filter on, with a declared schema. - **Scratch within one job or one machine:** Feather, after `reset_index()`. - **To people:** CSV or Excel, written at the edge. - **Shared, mutable state:** a database table owned by DDL, written with `append` or `delete_rows`. ## What would change the call - Many small appends per day favour a database or a table format over thousands of tiny Parquet files. - A consumer that cannot read Parquet forces an export step, not a different internal standard. - Very wide, rarely re-read intermediates may be cheapest as Feather. - A team with some jobs still on pandas 2.x should test the handoff in both directions before standardising, because text dtype inference differs between 2.x and 3.0.
- Why not let every job use engine='auto'?'auto' picks pyarrow when installed and fastparquet otherwise, and the two differ: fastparquet filters only at partition and row-group level, ignores `dtype_backend`, and lacks Period and Interval support. A worker missing PyArrow would silently change behaviour, so pin `engine='pyarrow'` and the PyArrow version.
- When is Feather the better choice than Parquet?For short-lived intermediates read back by pandas or other Arrow tools on the same platform, where write and read speed matter more than compression and partition pruning. It is documented as needing a default index, so call `reset_index()` first; for datasets shared across teams or kept long-term, Parquet's filters and broad reader support win.
- Chooses CSV for internal handoffs because it is readable and then re-pins dtypes in every reader
- Lets each job pick engine='auto' and assumes every worker behaves the same
- Writes Parquet with a non-range index and surprises non-pandas readers with an extra column
- Expects every categorical column to come back as category from Parquet
- Picks Excel as the exchange format between automated jobs
Assumes pandas 3.0, where text columns infer the str dtype (PyArrow-backed when installed); on 2.x they were object, which Parquet also wrote as strings but read back as object.