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:
7979 )
8080
8181
82- class PandasPyarrowBackedBuffer (Buffer ):
82+ class PandasBufferPyarrow (Buffer ):
8383 """
8484 Data in the buffer is guaranteed to be contiguous in memory.
8585 """
8686
8787 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 ,
8993 ) -> None :
9094 """
9195 Handle pyarrow chunked arrays.
@@ -98,7 +102,10 @@ def __init__(
98102 "Found multi-chunk pyarrow array, but `allow_copy` is False"
99103 )
100104 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 ]
102109 self ._length = len (arr )
103110 self ._dlpack = arr .__dlpack__
104111
@@ -130,7 +137,7 @@ def __dlpack_device__(self) -> tuple[DlpackDeviceType, int | None]:
130137
131138 def __repr__ (self ) -> str :
132139 return (
133- "PandasBuffer("
140+ "PandasBuffer[pyarrow] ("
134141 + str (
135142 {
136143 "bufsize" : self .bufsize ,
Original file line number Diff line number Diff line change 1919from pandas .api .types import is_string_dtype
2020from pandas .core .interchange .buffer import (
2121 PandasBuffer ,
22- PandasPyarrowBackedBuffer ,
22+ PandasBufferPyarrow ,
2323)
2424from pandas .core .interchange .dataframe_protocol import (
2525 Column ,
@@ -311,7 +311,9 @@ def _get_data_buffer(
311311 arr = self ._col .array
312312 if isinstance (self ._col .dtype , ArrowDtype ):
313313 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+ )
315317 return buffer , dtype
316318 if isinstance (self ._col .dtype , BaseMaskedDtype ):
317319 np_arr = arr ._data # type: ignore[attr-defined]
@@ -364,7 +366,9 @@ def _get_validity_buffer(self) -> tuple[PandasBuffer, Any]:
364366 dtype = (DtypeKind .BOOL , 1 , ArrowCTypes .BOOL , Endianness .NATIVE )
365367 if buf is None :
366368 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+ )
368372 return buffer , dtype
369373
370374 if isinstance (self ._col .dtype , BaseMaskedDtype ):
You can’t perform that action at this time.
0 commit comments