Skip to content

Commit 81fe543

Browse files
committed
Revert "FIX: Immutable buffers should not be set writeable"
This reverts commit 0a1ea75.
1 parent 0a1ea75 commit 81fe543

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

nibabel/streamlines/tck.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,10 @@ def _read(cls, fileobj, header, buffer_size=4):
432432
for point_part in point_parts:
433433
# Read floats.
434434
pts = np.frombuffer(point_part, dtype=dtype)
435+
# Enforce ability to write to underlying bytes object
436+
pts.flags.writeable = True
435437
# Convert data to little-endian if needed.
436-
yield pts.astype('<f4').reshape([-1, 3])
438+
yield pts.astype('<f4', copy=False).reshape([-1, 3])
437439

438440
n_streams += len(point_parts)
439441

nibabel/streamlines/tests/test_trk.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ def trk_with_bytes(self, trk_key='simple_trk_fname', endian='<'):
105105
with open(DATA[trk_key], 'rb') as fobj:
106106
trk_bytes = fobj.read()
107107
dt = trk_module.header_2_dtype.newbyteorder(endian)
108-
trk_struct = np.ndarray((1,), dt, buffer=trk_bytes).copy()
108+
trk_struct = np.ndarray((1,), dt, buffer=trk_bytes)
109+
trk_struct.flags.writeable = True
109110
return trk_struct, trk_bytes
110111

111112
def test_load_file_with_wrong_information(self):

nibabel/volumeutils.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -538,13 +538,9 @@ def array_from_file(shape, in_dtype, infile, offset=0, order='F', mmap=True):
538538
n_read,
539539
getattr(infile, 'name', 'object')))
540540
arr = np.ndarray(shape, in_dtype, buffer=data_bytes, order=order)
541-
if not needs_copy:
542-
try:
543-
arr.flags.writeable = True
544-
except ValueError:
545-
needs_copy = True
546541
if needs_copy:
547-
arr = arr.copy()
542+
return arr.copy()
543+
arr.flags.writeable = True
548544
return arr
549545

550546

0 commit comments

Comments
 (0)