File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed
Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change 1212
1313if TYPE_CHECKING :
1414 import numpy as np
15+ import pyarrow as pa
1516
1617
1718class PandasBuffer (Buffer ):
@@ -83,14 +84,21 @@ class PandasPyarrowBackedBuffer(Buffer):
8384 Data in the buffer is guaranteed to be contiguous in memory.
8485 """
8586
86- def __init__ (self , arr : Any , allow_copy : bool = True ) -> None :
87+ def __init__ (
88+ self , chunked_array : pa .ChunkedArray , * , allow_copy : bool = True
89+ ) -> None :
8790 """
88- Handle only regular columns (= numpy arrays) for now .
91+ Handle pyarrow chunked arrays.
8992 """
90-
91- # Store the numpy array in which the data resides as a private
92- # attribute, so we can use it to retrieve the public attributes
93- self ._buffer = arr .chunks [0 ].buffers ()[1 ]
93+ if len (chunked_array .chunks ) == 1 :
94+ arr = chunked_array .chunks [0 ]
95+ else :
96+ if not allow_copy :
97+ raise RuntimeError (
98+ "Found multi-chunk pyarrow array, but `allow_copy` is False"
99+ )
100+ arr = chunked_array .combine_chunks ()
101+ self ._buffer = arr .buffers ()[1 ]
94102 self ._length = len (arr )
95103
96104 @property
You can’t perform that action at this time.
0 commit comments