File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change 1
1
import pytest
2
2
import math
3
+ import ctypes
3
4
4
5
@pytest .mark .parametrize ("test_data" ,
5
6
[
@@ -98,7 +99,8 @@ def test_get_columns(df_from_dict):
98
99
assert dfX .get_column (1 ).dtype [0 ] == 2
99
100
100
101
def test_buffer (df_from_dict ):
101
- df = df_from_dict ({"a" : [0 , 1 ]})
102
+ arr = [0 , 1 , - 1 ]
103
+ df = df_from_dict ({"a" : arr })
102
104
dfX = df .__dataframe__ ()
103
105
colX = dfX .get_column (0 )
104
106
bufX = colX .get_buffers ()
@@ -107,6 +109,17 @@ def test_buffer(df_from_dict):
107
109
108
110
assert dataBuf .bufsize > 0
109
111
assert dataBuf .ptr != 0
110
- assert dataBuf .__dlpack_device__
112
+ device , _ = dataBuf .__dlpack_device__
111
113
112
114
assert dataDtype [0 ] == 0
115
+
116
+ if device == 1 : # CPU-only as we're going to directly read memory here
117
+ bitwidth = dataDtype [1 ]
118
+ ctype = {8 : ctypes .c_int8 ,
119
+ 16 : ctypes .c_int16 ,
120
+ 32 : ctypes .c_int32 ,
121
+ 64 : ctypes .c_int64 }[bitwidth ]
122
+
123
+ for idx , truth in enumerate (arr ):
124
+ val = ctype .from_address (dataBuf .ptr + idx * (bitwidth // 8 )).value
125
+ assert val == truth , f"Buffer at index { idx } mismatch"
You can’t perform that action at this time.
0 commit comments