Add PyCapsule Protocol support for Arrow inputs #1265
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Closes #1227
Rationale for this change
(From original issue)
PyArrow is a massive dependency (>100MB unpacked) and the only required dependency for datafusion-python. Many Python Arrow libraries implement the PyCapsule Interface, allowing users to choose lightweight alternatives like nanoarrow (~7MB), arro3, or pass data directly from Polars, DuckDB, etc.
This PR implements the first phase of making PyArrow optional by updating input parameters to accept any Arrow-compatible library via the PyCapsule Interface.
What changes are included in this PR?
ArrowSchemaExportable
register_csv
,register_parquet
,register_json
,register_avro
,register_listing_table
, and read methods to acceptArrowSchemaExportable
TYPE_CHECKING
block (optional at runtime for type hints only)Note: This PR covers input parameters only. Return types (ToPyArrow conversions) still reference pyarrow and will be addressed in a follow-up PR.
Are there any user-facing changes?
Breaking changes: None. All existing PyArrow usage continues to work.
New functionality: Users can now pass Arrow schemas from any library implementing
__arrow_c_schema__()
(nanoarrow, arro3, Polars, DuckDB, etc.) to datafusion methods.Type hints: Schema parameters now show
ArrowSchemaExportable | None
instead ofpa.Schema | None
, but accept both.