forked from pola-rs/polars
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(python): Expose Arrow C interface directly on Polars (pola-rs#17696
- Loading branch information
Showing
7 changed files
with
133 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# --8<-- [start:to_arrow] | ||
import polars as pl | ||
|
||
df = pl.DataFrame({"foo": [1, 2, 3], "bar": ["ham", "spam", "jam"]}) | ||
|
||
arrow_table = df.to_arrow() | ||
print(arrow_table) | ||
# --8<-- [end:to_arrow] | ||
|
||
# --8<-- [start:to_arrow_zero] | ||
arrow_table_zero_copy = df.to_arrow(compat_level=pl.CompatLevel.newest()) | ||
print(arrow_table_zero_copy) | ||
# --8<-- [end:to_arrow_zero] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Arrow producer/consumer | ||
|
||
## Using pyarrow | ||
|
||
Polars can move data in and out of arrow zero copy. This can be done either via pyarrow | ||
or natively. Let's first start by showing the pyarrow solution: | ||
|
||
{{code_block('user-guide/misc/arrow','to_arrow',[])}} | ||
|
||
``` | ||
pyarrow.Table | ||
foo: int64 | ||
bar: large_string | ||
---- | ||
foo: [[1,2,3]] | ||
bar: [["ham","spam","jam"]] | ||
``` | ||
|
||
Or if you want to ensure the output is zero-copy: | ||
|
||
{{code_block('user-guide/misc/arrow','to_arrow_zero',[])}} | ||
|
||
``` | ||
pyarrow.Table | ||
foo: int64 | ||
bar: string_view | ||
---- | ||
foo: [[1,2,3]] | ||
bar: [["ham","spam","jam"]] | ||
``` | ||
|
||
Importing from pyarrow can be achieved with `pl.from_arrow`. | ||
|
||
## Using Polars directly | ||
|
||
Polars can also consume and export to and import from the [Arrow C Data Interface](https://arrow.apache.org/docs/format/CDataInterface.html) | ||
directly. This is recommended for library maintainers that want to interop with Polars without requiring a pyarrow installation. | ||
|
||
- To export `ArrowArray` C structs, Polars exposes: `Series._export_arrow_to_c`. | ||
- To import an `ArrowArray` C struct, Polars exposes `Series._import_arrow_from_c`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters