Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Arrow PyCapsule interface #2376

Closed
kylebarron opened this issue Apr 2, 2024 · 2 comments · Fixed by #2534
Closed

Support for Arrow PyCapsule interface #2376

kylebarron opened this issue Apr 2, 2024 · 2 comments · Fixed by #2534
Labels
enhancement New feature or request

Comments

@kylebarron
Copy link
Contributor

Description

Looking at the code below, the write_deltalake function is hard-coded to support only specific pyarrow and pandas objects.

if isinstance(data, RecordBatchReader):
data = convert_pyarrow_recordbatchreader(data, large_dtypes)
elif isinstance(data, pa.RecordBatch):
data = convert_pyarrow_recordbatch(data, large_dtypes)
elif isinstance(data, pa.Table):
data = convert_pyarrow_table(data, large_dtypes)
elif isinstance(data, ds.Dataset):
data = convert_pyarrow_dataset(data, large_dtypes)
elif _has_pandas and isinstance(data, pd.DataFrame):
if schema is not None:
data = convert_pyarrow_table(
pa.Table.from_pandas(data, schema=schema), large_dtypes=large_dtypes
)
else:
data = convert_pyarrow_table(
pa.Table.from_pandas(data), large_dtypes=large_dtypes
)
elif isinstance(data, Iterable):
if schema is None:
raise ValueError("You must provide schema if data is Iterable")
else:
raise TypeError(
f"{type(data).__name__} is not a valid input. Only PyArrow RecordBatchReader, RecordBatch, Iterable[RecordBatch], Table, Dataset or Pandas DataFrame are valid inputs for source."
)

With the Arrow PyCapsule interface, you can support any Arrow-based Python input, regardless of the library implementation.

Use Case

I'm working on a Python library for Arrow-backed geospatial operations, and support for the PyCapsule interface would allow interfacing with my or any other Python Arrow library without needing hard-coded support.

Related Issue(s)

@kylebarron kylebarron added the enhancement New feature or request label Apr 2, 2024
@ion-elgreco
Copy link
Collaborator

@kylebarron hey Kyle, are you willing to make this contribution here?

@kylebarron
Copy link
Contributor Author

I put up a short initial PR for the write side to get things moving. I think we may be able to wrap some additional classes to export through the pycapsule interface as well (deferring to to_pyarrow under the hood)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants