(arr, schema_accessor, bad_type, good_type)
| 613 | ), |
| 614 | ], ids=['array', 'record_batch']) |
| 615 | def test_roundtrip_device_array_capsule(arr, schema_accessor, bad_type, good_type): |
| 616 | gc.collect() # Make sure no Arrow data dangles in a ref cycle |
| 617 | old_allocated = pa.total_allocated_bytes() |
| 618 | |
| 619 | import_array = type(arr)._import_from_c_device_capsule |
| 620 | |
| 621 | schema_capsule, capsule = arr.__arrow_c_device_array__() |
| 622 | assert PyCapsule_IsValid(schema_capsule, b"arrow_schema") == 1 |
| 623 | assert PyCapsule_IsValid(capsule, b"arrow_device_array") == 1 |
| 624 | arr_out = import_array(schema_capsule, capsule) |
| 625 | assert arr_out.equals(arr) |
| 626 | |
| 627 | assert pa.total_allocated_bytes() > old_allocated |
| 628 | del arr_out |
| 629 | |
| 630 | assert pa.total_allocated_bytes() == old_allocated |
| 631 | |
| 632 | capsule = arr.__arrow_c_array__() |
| 633 | |
| 634 | assert pa.total_allocated_bytes() > old_allocated |
| 635 | del capsule |
| 636 | assert pa.total_allocated_bytes() == old_allocated |
| 637 | |
| 638 | with pytest.raises(ValueError, |
| 639 | match=r"Could not cast.* string to requested .* int32"): |
| 640 | arr.__arrow_c_device_array__(bad_type.__arrow_c_schema__()) |
| 641 | |
| 642 | schema_capsule, array_capsule = arr.__arrow_c_device_array__( |
| 643 | good_type.__arrow_c_schema__()) |
| 644 | arr_out = import_array(schema_capsule, array_capsule) |
| 645 | assert schema_accessor(arr_out) == good_type |
| 646 | |
| 647 | |
| 648 | @pytest.mark.parametrize('constructor', [ |
nothing calls this directly
no test coverage detected