(arr, schema_accessor, bad_type, good_type)
| 604 | ), |
| 605 | ], ids=['array', 'record_batch']) |
| 606 | def test_roundtrip_array_capsule(arr, schema_accessor, bad_type, good_type): |
| 607 | gc.collect() # Make sure no Arrow data dangles in a ref cycle |
| 608 | old_allocated = pa.total_allocated_bytes() |
| 609 | |
| 610 | import_array = type(arr)._import_from_c_capsule |
| 611 | |
| 612 | schema_capsule, capsule = arr.__arrow_c_array__() |
| 613 | assert PyCapsule_IsValid(schema_capsule, b"arrow_schema") == 1 |
| 614 | assert PyCapsule_IsValid(capsule, b"arrow_array") == 1 |
| 615 | arr_out = import_array(schema_capsule, capsule) |
| 616 | assert arr_out.equals(arr) |
| 617 | |
| 618 | assert pa.total_allocated_bytes() > old_allocated |
| 619 | del arr_out |
| 620 | |
| 621 | assert pa.total_allocated_bytes() == old_allocated |
| 622 | |
| 623 | capsule = arr.__arrow_c_array__() |
| 624 | |
| 625 | assert pa.total_allocated_bytes() > old_allocated |
| 626 | del capsule |
| 627 | assert pa.total_allocated_bytes() == old_allocated |
| 628 | |
| 629 | with pytest.raises(ValueError, |
| 630 | match=r"Could not cast.* string to requested .* int32"): |
| 631 | arr.__arrow_c_array__(bad_type.__arrow_c_schema__()) |
| 632 | |
| 633 | schema_capsule, array_capsule = arr.__arrow_c_array__( |
| 634 | good_type.__arrow_c_schema__()) |
| 635 | arr_out = import_array(schema_capsule, array_capsule) |
| 636 | assert schema_accessor(arr_out) == good_type |
| 637 | |
| 638 | |
| 639 | @pytest.mark.parametrize('arr,schema_accessor,bad_type,good_type', [ |
nothing calls this directly
no test coverage detected