Skip to content

Commit 9896ec0

Browse files
committed
combine chunks
1 parent cb544a5 commit 9896ec0

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

pandas/core/interchange/buffer.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
if TYPE_CHECKING:
1414
import numpy as np
15+
import pyarrow as pa
1516

1617

1718
class 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

0 commit comments

Comments
 (0)