Sub topic 15
Limits and trade-offs: when Arrow does not help
This chapter assumes you know Arrow arrays, schemas and tables, the NumPy and pandas conversions, and the roles of Parquet, the C data interface, Flight and ADBC. Arrow removes conversion cost between tools that already use it. It does not make every workload faster.
Copies still happen
Zero-copy only works when the source layout matches what the target expects. Common cases that copy:
- Arrays with nulls, because NumPy integer arrays have no validity bitmap.
- String columns, because Arrow stores offsets plus one data buffer, while pandas object columns hold Python objects.
- Chunked columns, because a table column made of several chunks must be joined to become one NumPy array.
The following code shows the check. zero_copy_only=True raises an error instead of copying quietly.
import pyarrow as pa
arr = pa.array([1, None, 3], type=pa.int64())
try:
arr.to_numpy(zero_copy_only=True)
except pa.ArrowInvalid as err:
print("copy required:", err)
print(arr.to_numpy(zero_copy_only=False))The second call succeeds, but it allocates new memory and converts the null to nan, so the integers become floats.
Immutability and small data
Arrow buffers are meant to be shared, so arrays are immutable. Changing one value means building a new array. A workload of many single-row updates fits a row store or a database better. Arrow suits scans, filters and aggregations over many rows.
Arrow also adds fixed costs: schema handling, buffer allocation and a Python-to-C++ boundary on each call. For a few hundred rows, a plain Python list or a small pandas frame is often just as fast, and simpler.
Memory and ownership
A zero-copy view keeps the original buffer alive. A small slice of a large array can hold the whole parent buffer in memory. Memory-mapped files tie your data to a file that must stay in place. Across the C data interface, the consumer must call the release callback exactly once. Avoid using memory after its owner frees it.
Arrow is not a storage format or an engine
| Need | Better fit | Reason |
|---|---|---|
| Long-term storage | Parquet | Compressed and encoded for disk, so files are smaller. |
| Fast scans on disk | Parquet with a dataset scan | Filter and projection skip unneeded data. |
| Query execution | A query engine such as DuckDB | Arrow has compute functions, but no SQL planner. |
| Moving data between processes | IPC, Flight | Streams of record batches, with the schema sent first. |
| Reading from a database | ADBC | Returns Arrow batches directly, with no row-by-row conversion. |
Arrow IPC files are usually larger than the same data in Parquet. The IPC format is useful when read speed and memory mapping matter more than file size.
Compatibility and cost of the wrong tool
Both sides must support the same Arrow types. Some types, such as extension types or newer string layouts, may not be handled by an older library. Check library versions before relying on a handoff. If both tools already agree on a format and the data is small, adding Arrow brings a new dependency and no gain.
Exercise
A table has 50 million rows with an integer column that contains some nulls, and you call to_numpy(zero_copy_only=True) on that column. What happens, and what are two ways to proceed?
Show answer
It raises ArrowInvalid, because NumPy integers cannot represent nulls without conversion. You can call to_numpy(zero_copy_only=False) and accept a copy with floats and nan, or you can fill or drop the nulls first (for example with pyarrow.compute.fill_null) so the array can be viewed without a copy. A third option is to stay in Arrow and use compute functions, which handle nulls natively.
Exercise
Your application stores 200 rows of data and updates single rows often. A colleague suggests Arrow for speed. Give two reasons it probably will not help.
Show answer
Arrow arrays are immutable, so each update means building a new array. With only 200 rows, the fixed overhead of schemas and buffer handling outweighs any columnar benefit. A plain Python structure or a row-oriented store fits this workload better.