()
| 178 | |
| 179 | @pytest.mark.numpy |
| 180 | def test_to_numpy_zero_copy(): |
| 181 | arr = pa.array(range(10)) |
| 182 | |
| 183 | np_arr = arr.to_numpy() |
| 184 | |
| 185 | # check for zero copy (both arrays using same memory) |
| 186 | arrow_buf = arr.buffers()[1] |
| 187 | assert arrow_buf.address == np_arr.ctypes.data |
| 188 | |
| 189 | arr = None |
| 190 | import gc |
| 191 | gc.collect() |
| 192 | |
| 193 | # Ensure base is still valid |
| 194 | assert np_arr.base is not None |
| 195 | expected = np.arange(10) |
| 196 | np.testing.assert_array_equal(np_arr, expected) |
| 197 | |
| 198 | |
| 199 | @pytest.mark.numpy |