Sub topic 10
How Parquet keeps dtypes and what it cannot store
This chapter assumes you can already write a DataFrame with to_parquet and have pyarrow installed. Here you will see which dtypes survive a Parquet round trip and which data makes the write fail.
Why dtypes survive
A CSV file holds only text, so read_csv has to guess each column's type. A Parquet file holds a schema, which lists every column's name and type, next to the data. When you use the pyarrow engine, pandas also stores a block of pandas metadata in the file. That block records details such as the index and the original pandas dtypes. read_parquet uses both to rebuild the DataFrame.
import pandas as pd
df = pd.DataFrame({
"id": pd.array([1, 2, None], dtype="Int64"),
"name": pd.array(["Ana", "Ben", None], dtype="string"),
"plan": pd.Categorical(["free", "pro", "free"]),
"seen_at": pd.to_datetime(
["2026-01-05 09:00", "2026-01-06 10:30", None]
).tz_localize("UTC"),
})
df.to_parquet("users.parquet", index=False)
back = pd.read_parquet("users.parquet")
print(df.dtypes)
print(back.dtypes)The two dtypes listings match. The nullable integer, the string dtype, the category and the timezone-aware datetime all come back without any dtype= or parse_dates= arguments. The missing integer stays <NA> and does not turn the column into floats.
flowchart TDReplace that line: the diagram below shows the path.
What is preserved
| pandas data | After a Parquet round trip |
|---|---|
| `int64`, `float64`, `bool` | Kept |
| Nullable `Int64`, `boolean`, `string` | Kept, with `<NA>` values intact |
| `category` | Kept as a category |
| `datetime64`, including timezone | Kept |
| Lists and dicts of simple values | Stored as list and struct columns |
| A non-default index | Kept, unless you pass `index=False` |
Pass index=False when the index is only a row counter. With the default index=None, a plain RangeIndex is stored as small metadata, and any other index is stored as an extra column.
What it cannot store
Parquet needs every column to have one clear type. The write fails or misbehaves in these cases:
- Mixed-type object columns. A column holding
1,"a"and2.5has no single Parquet type. - Arbitrary Python objects. Sets, custom class instances and similar values cannot be converted.
- Non-string column names. Integer column labels raise an error in the
pyarrowengine. Rename them first. - Duplicate column names. Column names must be unique.
import pandas as pd
messy = pd.DataFrame({"mixed": [1, "a", 2.5]})
try:
messy.to_parquet("messy.parquet", index=False)
except Exception as exc:
print("Write failed:", type(exc).__name__)
messy["mixed"] = messy["mixed"].astype("string")
messy.to_parquet("messy.parquet", index=False)
print(pd.read_parquet("messy.parquet")["mixed"].tolist())The first write fails because pyarrow cannot infer one type. After you convert the column to string, the write works. Every value comes back as text, so 2.5 is now "2.5". Decide on the target type yourself and do not let a failed write force the choice.
Check your understanding
Exercise
A DataFrame has a nullable Int64 column with one missing value and a column holding a mix of integers and strings. You call to_parquet. What happens to each column, and what do you do about it?
Show answer
The Int64 column is stored with its null and comes back as Int64 with <NA>. The mixed column makes the pyarrow write fail because it has no single type. Convert it to one dtype first, for example df["col"] = df["col"].astype("string"), then write again.