From 561239ede6d2133fea3c81f873c793f4f6deeddd Mon Sep 17 00:00:00 2001 From: Dane Pitkin Date: Tue, 23 Jul 2024 11:31:17 -0400 Subject: [PATCH] GH-43727: [Python] RecordBatch failse gracefully on non-cpu devices --- python/pyarrow/lib.pxd | 2 ++ python/pyarrow/table.pxi | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/python/pyarrow/lib.pxd b/python/pyarrow/lib.pxd index 2cb302d20a8ac..e50a8f778e359 100644 --- a/python/pyarrow/lib.pxd +++ b/python/pyarrow/lib.pxd @@ -519,6 +519,7 @@ cdef class Table(_Tabular): CTable* table cdef void init(self, const shared_ptr[CTable]& table) + cdef void _assert_cpu(self) noexcept cdef class RecordBatch(_Tabular): @@ -528,6 +529,7 @@ cdef class RecordBatch(_Tabular): Schema _schema cdef void init(self, const shared_ptr[CRecordBatch]& table) + cdef void _assert_cpu(self) except * cdef class Device(_Weakrefable): diff --git a/python/pyarrow/table.pxi b/python/pyarrow/table.pxi index 8f7c44e55dc8d..0b20ec934f955 100644 --- a/python/pyarrow/table.pxi +++ b/python/pyarrow/table.pxi @@ -3905,6 +3905,10 @@ cdef class RecordBatch(_Tabular): """ return self.device_type == DeviceAllocationType.CPU + cdef void _assert_cpu(self) except *: + if self.sp_batch.get().device_type() != CDeviceAllocationType_kCPU: + raise NotImplementedError("Implemented only for data on CPU device") + def _reconstruct_record_batch(columns, schema): """ @@ -5679,6 +5683,9 @@ cdef class Table(_Tabular): """ return self.to_reader().__arrow_c_stream__(requested_schema) + cdef void _assert_cpu(self) noexcept: + return # TODO GH-43728 + def _reconstruct_table(arrays, schema): """