Skip to content

Commit cb544a5

Browse files
committed
working?
1 parent 03290c6 commit cb544a5

File tree

2 files changed

+21
-24
lines changed

2 files changed

+21
-24
lines changed

pandas/core/interchange/buffer.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,50 +83,51 @@ class PandasPyarrowBackedBuffer(Buffer):
8383
Data in the buffer is guaranteed to be contiguous in memory.
8484
"""
8585

86-
def __init__(self, x: Any, allow_copy: bool = True) -> None:
86+
def __init__(self, arr: Any, allow_copy: bool = True) -> None:
8787
"""
8888
Handle only regular columns (= numpy arrays) for now.
8989
"""
9090

9191
# Store the numpy array in which the data resides as a private
9292
# attribute, so we can use it to retrieve the public attributes
93-
self._x = x
93+
self._buffer = arr.chunks[0].buffers()[1]
94+
self._length = len(arr)
9495

9596
@property
9697
def bufsize(self) -> int:
9798
"""
9899
Buffer size in bytes.
99100
"""
100-
return self._x.size
101+
return self._buffer.size * self._length
101102

102103
@property
103104
def ptr(self) -> int:
104105
"""
105106
Pointer to start of the buffer as an integer.
106107
"""
107-
return self._x.address
108+
return self._buffer.address
108109

109110
def __dlpack__(self) -> Any:
110111
"""
111112
Represent this structure as DLPack interface.
112113
"""
113-
return self._x.__dlpack__()
114+
return self._buffer.__dlpack__()
114115

115116
def __dlpack_device__(self) -> tuple[DlpackDeviceType, int | None]:
116117
"""
117118
Device type and device ID for where the data in the buffer resides.
118119
"""
119120
return (DlpackDeviceType.CPU, None)
120121

121-
# def __repr__(self) -> str:
122-
# return (
123-
# "PandasBuffer("
124-
# + str(
125-
# {
126-
# "bufsize": self.bufsize,
127-
# "ptr": self.ptr,
128-
# "device": self.__dlpack_device__()[0].name,
129-
# }
130-
# )
131-
# + ")"
132-
# )
122+
def __repr__(self) -> str:
123+
return (
124+
"PandasBuffer("
125+
+ str(
126+
{
127+
"bufsize": self.bufsize,
128+
"ptr": self.ptr,
129+
"device": self.__dlpack_device__()[0].name,
130+
}
131+
)
132+
+ ")"
133+
)

pandas/core/interchange/column.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,7 @@ def describe_null(self):
199199
return column_null_dtype, null_value
200200
kind = self.dtype[0]
201201
if isinstance(self._col.dtype, ArrowDtype):
202-
column_null_dtype = ColumnNullType.USE_BITMASK
203-
null_value = 0
204-
if ~self._col.isna().any():
205-
return column_null_dtype, None
206-
return column_null_dtype, null_value
202+
return ColumnNullType.USE_BITMASK, 0
207203
try:
208204
null, value = _NULL_DESCRIPTION[kind]
209205
except KeyError as err:
@@ -315,7 +311,7 @@ def _get_data_buffer(
315311
arr = self._col.array
316312
if isinstance(self._col.dtype, ArrowDtype):
317313
arr = self._col.array
318-
buffer = PandasPyarrowBackedBuffer(arr._pa_array.chunks[0].buffers()[1])
314+
buffer = PandasPyarrowBackedBuffer(arr._pa_array)
319315
return buffer, dtype
320316
if isinstance(self._col.dtype, BaseMaskedDtype):
321317
np_arr = arr._data # type: ignore[attr-defined]
@@ -368,7 +364,7 @@ def _get_validity_buffer(self) -> tuple[PandasBuffer, Any]:
368364
dtype = (DtypeKind.BOOL, 1, ArrowCTypes.BOOL, Endianness.NATIVE)
369365
if buf is None:
370366
return buf, dtype
371-
buffer = PandasPyarrowBackedBuffer(buf)
367+
buffer = PandasPyarrowBackedBuffer(arr._pa_array)
372368
return buffer, dtype
373369

374370
if isinstance(self._col.dtype, BaseMaskedDtype):

0 commit comments

Comments
 (0)