You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "kylebarron (via GitHub)" <gi...@apache.org> on 2024/07/11 20:55:47 UTC
[I] Implement Arrow PyCapsule Interface [datafusion-python]
kylebarron opened a new issue, #752:
URL: https://github.com/apache/datafusion-python/issues/752
**Is your feature request related to a problem or challenge? Please describe what you are trying to do.**
The [Arrow PyCapsule Interface](https://arrow.apache.org/docs/format/CDataInterface/PyCapsuleInterface.html) is a new spec to simplify Arrow interop between compiled Python libraries.
For example, there's a `from_arrow_table` method https://github.com/apache/datafusion-python/blob/faa5a3f5352342328e183cbeceb3219d7bd05ff8/src/context.rs#L467-L473 but this narrowly allows only _pyarrow Table_ objects (it expects a `to_batches` method).
A `from_arrow` method that looks for the `__arrow_c_stream__` method would work _out of the box_ on any Arrow-based Python library implementing this spec. That includes pyarrow `Table`s and `RecordBatchReader`s, ibis Tables (https://github.com/ibis-project/ibis/pull/9143), [nanoarrow objects](https://github.com/apache/arrow-nanoarrow), and hopefully soon duckdb and polars objects as well (https://github.com/pola-rs/polars/issues/12530).
Implementing `__arrow_c_stream__` on datafusion exports means that any of those other libraries would _just work_ on datafusion classes, without needing to know anything specific of datafusion.
**Describe the solution you'd like**
PyCapsule _import_ has been implemented in arrow upstream, but export hasn't been implemented. I've implemented import and export in [pyo3-arrow](https://docs.rs/pyo3-arrow/latest/pyo3_arrow/) (separated for a [few reasons](https://docs.rs/pyo3-arrow/latest/pyo3_arrow/#why-not-use-arrow-rss-python-integration)). I'm not sure if datafusion-python wants another dependency, but the content of pyo3-arrow could also be copied into here. Exporting raw pycapsule objects could be implemented in upstream `arrow` if preferred.
**Describe alternatives you've considered**
**Additional context**
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Implement Arrow PyCapsule Interface [datafusion-python]
Posted by "timsaucer (via GitHub)" <gi...@apache.org>.
timsaucer commented on issue #752:
URL: https://github.com/apache/datafusion-python/issues/752#issuecomment-2297704919
Dropping note for myself: Currently ignoring the requested schema. That needs to be resolved before committing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Implement Arrow PyCapsule Interface [datafusion-python]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove closed issue #752: Implement Arrow PyCapsule Interface
URL: https://github.com/apache/datafusion-python/issues/752
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Implement Arrow PyCapsule Interface [datafusion-python]
Posted by "timsaucer (via GitHub)" <gi...@apache.org>.
timsaucer commented on issue #752:
URL: https://github.com/apache/datafusion-python/issues/752#issuecomment-2297702463
This turned out to be easier than I expected. Right now I have it importing using the upstream pycapsule implementation and I'm exporting DataFrame. Is there anything else you think needs exporting?
```
from datafusion import lit, SessionContext
import nanoarrow as na
import pyarrow as pa
ctx = SessionContext()
table = pa.table({"a": [1, 2, 3, 4], "b": ["a", "b", "c", "d"]})
print(table)
df = ctx.from_arrow_table(table).with_column("c", lit(3))
df.show()
nd = na.Array(df)
print(nd)
```
Produces
```
pyarrow.Table
a: int64
b: string
----
a: [[1,2,3,4]]
b: [["a","b","c","d"]]
DataFrame()
+---+---+---+
| a | b | c |
+---+---+---+
| 1 | a | 3 |
| 2 | b | 3 |
| 3 | c | 3 |
| 4 | d | 3 |
+---+---+---+
nanoarrow.Array<non-nullable struct<a: int64, b: string, c: int64>>[4]
{'a': 1, 'b': 'a', 'c': 3}
{'a': 2, 'b': 'b', 'c': 3}
{'a': 3, 'b': 'c', 'c': 3}
{'a': 4, 'b': 'd', 'c': 3}
```
I'll put up a PR after I've had time to write up some good unit tests.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org