()
| 903 | |
| 904 | |
| 905 | def test_device_interface_batch_array(): |
| 906 | cffi = pytest.importorskip("pyarrow.cffi", exc_type=ImportError) |
| 907 | ffi = cffi.ffi |
| 908 | |
| 909 | c_schema = ffi.new("struct ArrowSchema*") |
| 910 | ptr_schema = int(ffi.cast("uintptr_t", c_schema)) |
| 911 | c_array = ffi.new("struct ArrowDeviceArray*") |
| 912 | ptr_array = int(ffi.cast("uintptr_t", c_array)) |
| 913 | |
| 914 | batch = make_recordbatch(10) |
| 915 | schema = batch.schema |
| 916 | cbuf = cuda.serialize_record_batch(batch, global_context) |
| 917 | cbatch = cuda.read_record_batch(cbuf, schema) |
| 918 | |
| 919 | # Schema is known up front |
| 920 | cbatch._export_to_c_device(ptr_array) |
| 921 | |
| 922 | # verify exported struct |
| 923 | assert c_array.device_type == 2 # ARROW_DEVICE_CUDA 2 |
| 924 | assert c_array.device_id == global_context.device_number |
| 925 | assert c_array.array.length == 10 |
| 926 | |
| 927 | # Delete recreate C++ object from exported pointer |
| 928 | del cbatch |
| 929 | cbatch_new = pa.RecordBatch._import_from_c_device(ptr_array, schema) |
| 930 | assert cbatch_new.schema == schema |
| 931 | batch_new = cbatch_new.copy_to(pa.default_cpu_memory_manager()) |
| 932 | assert batch_new.equals(batch) |
| 933 | |
| 934 | del cbatch_new |
| 935 | # Now released |
| 936 | with pytest.raises(ValueError, match="Cannot import released ArrowArray"): |
| 937 | pa.RecordBatch._import_from_c_device(ptr_array, schema) |
| 938 | |
| 939 | # Schema is exported and imported at the same time |
| 940 | cbatch = cuda.read_record_batch(cbuf, schema) |
| 941 | cbatch._export_to_c_device(ptr_array, ptr_schema) |
| 942 | # Delete and recreate C++ objects from exported pointers |
| 943 | del cbatch |
| 944 | cbatch_new = pa.RecordBatch._import_from_c_device(ptr_array, ptr_schema) |
| 945 | assert cbatch_new.schema == schema |
| 946 | batch_new = cbatch_new.copy_to(pa.default_cpu_memory_manager()) |
| 947 | assert batch_new.equals(batch) |
| 948 | |
| 949 | del cbatch_new |
| 950 | # Now released |
| 951 | with pytest.raises(ValueError, match="Cannot import released ArrowSchema"): |
| 952 | pa.RecordBatch._import_from_c_device(ptr_array, ptr_schema) |
| 953 | |
| 954 | # Not a struct type |
| 955 | pa.int32()._export_to_c(ptr_schema) |
| 956 | with pytest.raises(ValueError, |
| 957 | match="ArrowSchema describes non-struct type"): |
| 958 | pa.RecordBatch._import_from_c_device(ptr_array, ptr_schema) |
| 959 | |
| 960 | |
| 961 | def test_print_array(): |
nothing calls this directly
no test coverage detected