| 241 | |
| 242 | @pytest.mark.numpy |
| 243 | def test_to_numpy_writable(): |
| 244 | arr = pa.array(range(10)) |
| 245 | np_arr = arr.to_numpy() |
| 246 | |
| 247 | # by default not writable for zero-copy conversion |
| 248 | with pytest.raises(ValueError): |
| 249 | np_arr[0] = 10 |
| 250 | |
| 251 | np_arr2 = arr.to_numpy(zero_copy_only=False, writable=True) |
| 252 | np_arr2[0] = 10 |
| 253 | assert arr[0].as_py() == 0 |
| 254 | |
| 255 | # when asking for writable, cannot do zero-copy |
| 256 | with pytest.raises(ValueError): |
| 257 | arr.to_numpy(zero_copy_only=True, writable=True) |
| 258 | |
| 259 | |
| 260 | @pytest.mark.numpy |