File tree Expand file tree Collapse file tree 2 files changed +18
-7
lines changed Expand file tree Collapse file tree 2 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -79,13 +79,17 @@ def __repr__(self) -> str:
79
79
)
80
80
81
81
82
- class PandasPyarrowBackedBuffer (Buffer ):
82
+ class PandasBufferPyarrow (Buffer ):
83
83
"""
84
84
Data in the buffer is guaranteed to be contiguous in memory.
85
85
"""
86
86
87
87
def __init__ (
88
- self , chunked_array : pa .ChunkedArray , * , allow_copy : bool = True
88
+ self ,
89
+ chunked_array : pa .ChunkedArray ,
90
+ * ,
91
+ is_validity : bool ,
92
+ allow_copy : bool = True ,
89
93
) -> None :
90
94
"""
91
95
Handle pyarrow chunked arrays.
@@ -98,7 +102,10 @@ def __init__(
98
102
"Found multi-chunk pyarrow array, but `allow_copy` is False"
99
103
)
100
104
arr = chunked_array .combine_chunks ()
101
- self ._buffer = arr .buffers ()[1 ]
105
+ if is_validity :
106
+ self ._buffer = arr .buffers ()[0 ]
107
+ else :
108
+ self ._buffer = arr .buffers ()[1 ]
102
109
self ._length = len (arr )
103
110
self ._dlpack = arr .__dlpack__
104
111
@@ -130,7 +137,7 @@ def __dlpack_device__(self) -> tuple[DlpackDeviceType, int | None]:
130
137
131
138
def __repr__ (self ) -> str :
132
139
return (
133
- "PandasBuffer("
140
+ "PandasBuffer[pyarrow] ("
134
141
+ str (
135
142
{
136
143
"bufsize" : self .bufsize ,
Original file line number Diff line number Diff line change 19
19
from pandas .api .types import is_string_dtype
20
20
from pandas .core .interchange .buffer import (
21
21
PandasBuffer ,
22
- PandasPyarrowBackedBuffer ,
22
+ PandasBufferPyarrow ,
23
23
)
24
24
from pandas .core .interchange .dataframe_protocol import (
25
25
Column ,
@@ -311,7 +311,9 @@ def _get_data_buffer(
311
311
arr = self ._col .array
312
312
if isinstance (self ._col .dtype , ArrowDtype ):
313
313
arr = self ._col .array
314
- buffer = PandasPyarrowBackedBuffer (arr ._pa_array )
314
+ buffer = PandasBufferPyarrow (
315
+ arr ._pa_array , is_validity = False , allow_copy = self ._allow_copy
316
+ )
315
317
return buffer , dtype
316
318
if isinstance (self ._col .dtype , BaseMaskedDtype ):
317
319
np_arr = arr ._data # type: ignore[attr-defined]
@@ -364,7 +366,9 @@ def _get_validity_buffer(self) -> tuple[PandasBuffer, Any]:
364
366
dtype = (DtypeKind .BOOL , 1 , ArrowCTypes .BOOL , Endianness .NATIVE )
365
367
if buf is None :
366
368
return buf , dtype
367
- buffer = PandasPyarrowBackedBuffer (arr ._pa_array )
369
+ buffer = PandasBufferPyarrow (
370
+ arr ._pa_array , is_validity = True , allow_copy = self ._allow_copy
371
+ )
368
372
return buffer , dtype
369
373
370
374
if isinstance (self ._col .dtype , BaseMaskedDtype ):
You can’t perform that action at this time.
0 commit comments