-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add to_arrow method to pylibcudf core types #19787
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
Changes from 12 commits
150ed74
df69c49
c599010
7da3337
4b5a6b4
f3dcab1
fc7e3fe
f92428f
cb05938
5e0624e
50c47e1
360ff31
09bc263
ef34f7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,7 +36,15 @@ from pylibcudf._interop_helpers cimport ( | |
| _release_device_array, | ||
| _metadata_to_libcudf, | ||
| ) | ||
| from ._interop_helpers import ArrowLike, ColumnMetadata | ||
| from ._interop_helpers import ArrowLike, ColumnMetadata, _ObjectWithArrowMetadata | ||
|
|
||
| try: | ||
| import pyarrow as pa | ||
| pa_err = None | ||
| except ImportError as e: | ||
| pa = None | ||
| pa_err = e | ||
|
|
||
|
|
||
| __all__ = ["Table"] | ||
|
|
||
|
|
@@ -61,6 +69,22 @@ cdef class Table: | |
| raise ValueError("All columns must be pylibcudf Column objects") | ||
| self._columns = columns | ||
|
|
||
| def to_arrow( | ||
| self, | ||
| metadata: list[ColumnMetadata | str] | None = None | ||
| ) -> ArrowLike: | ||
| """Create a PyArrow table from a pylibcudf table.""" | ||
| if pa_err is not None: | ||
| raise RuntimeError( | ||
| "pyarrow was not found on your system. Please " | ||
| "pip install pylibcudf with the [pyarrow] extra for a " | ||
| "compatible pyarrow version." | ||
| ) from pa_err | ||
| # TODO: Once the arrow C device interface registers more | ||
| # types that it supports, we can call pa.array(self) if | ||
| # no metadata is passed. | ||
|
Comment on lines
+83
to
+86
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this comment referring to? I don't understand I'm afraid.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a typo that should be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean is that once arrow can consume more kinds of device arrays, we can call In [1]: import pylibcudf as plc
In [2]: import pyarrow as pa
In [3]: pa.table(plc.Table([plc.Column.from_iterable_of_py([1,2])]))
---------------------------------------------------------------------------
ArrowKeyError Traceback (most recent call last)
Cell In[3], line 1
----> 1 pa.table(plc.Table([plc.Column.from_iterable_of_py([1,2])]))
File ~/.conda/envs/rapids/lib/python3.13/site-packages/pyarrow/table.pxi:6235, in pyarrow.lib.table()
File ~/.conda/envs/rapids/lib/python3.13/site-packages/pyarrow/table.pxi:6054, in pyarrow.lib.record_batch()
File ~/.conda/envs/rapids/lib/python3.13/site-packages/pyarrow/table.pxi:4044, in pyarrow.lib.RecordBatch._import_from_c_device_capsule()
File ~/.conda/envs/rapids/lib/python3.13/site-packages/pyarrow/error.pxi:155, in pyarrow.lib.pyarrow_internal_check_status()
File ~/.conda/envs/rapids/lib/python3.13/site-packages/pyarrow/error.pxi:92, in pyarrow.lib.check_status()
ArrowKeyError: Device type 2is not registered
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I see. Yeah... I'm not sure that'll ever be supported, but if it is then great. The best bet might be backing pyarrow with pylibcudf for GPU bits! |
||
| return pa.table(_ObjectWithArrowMetadata(self, metadata)) | ||
|
|
||
| @staticmethod | ||
| def from_arrow(obj: ArrowLike, dtype: DataType | None = None) -> Table: | ||
| """ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.