-
-
Notifications
You must be signed in to change notification settings - Fork 0
DataFrames
.sheet(name, data) accepts pandas and polars DataFrames directly.
import pandas as pd, polars as pl
from rustpy_xlsxwriter import FastExcel
FastExcel("pandas.xlsx").sheet("S", pd.DataFrame({"a": [1, 2], "b": ["x", "y"]})).save()
FastExcel("polars.xlsx").sheet("S", pl.DataFrame({"a": [1, 2], "b": ["x", "y"]})).save()The writer inspects the object in this order (data_types.rs):
-
__arrow_c_stream__→ Arrow zero-copy (fastest) -
get_column+schema→ polars fallback -
columns→ pandas fallback - otherwise → records (list/generator of dicts)
pandas ≥ 2.0 and polars both expose the Arrow C-Stream interface, so column data is read straight from the Arrow buffers with no per-value Python conversion. This is the fast path and is taken automatically — you don't do anything special.
Supported Arrow column types: all integer/unsigned widths, Float16/32/64, Boolean, Utf8/LargeUtf8/Utf8View, Date32/Date64, and Timestamp (s/ms/µs/ns). Unsupported types are written as empty cells.
If the Arrow path is unavailable (e.g. old pandas without __arrow_c_stream__, or exotic dtypes), the writer materializes each column as a Python list (to_list/tolist). That path is O(rows) memory per column — not constant memory. Modern pandas/polars hit the Arrow path instead, so this only affects legacy setups.
Temporal columns get the datetime_format applied automatically (default ISO yyyy-mm-ddThh:mm:ss). Override per sheet:
FastExcel("dates.xlsx").format(datetime_format="dd/mm/yyyy").sheet("S", df).save()NaN and ±Inf floats are written as empty cells (both Excel and CSV).