nipy/nibabel

Numpy pre-release breaks setting some arrays writable

Closed this issue · 8 comments

Most likely culprit is numpy/numpy#11739, which was merged 7 days ago.

Example failures:

ERROR: test_load_simple_file (nibabel.streamlines.tests.test_streamlines.TestLoadSave)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/nipy/nibabel/venv/lib/python2.7/site-packages/nibabel/streamlines/tests/test_streamlines.py", line 152, in test_load_simple_file
    lazy_load=lazy_load)
  File "/home/travis/build/nipy/nibabel/venv/lib/python2.7/site-packages/nibabel/streamlines/__init__.py", line 96, in load
    return tractogram_file.load(fileobj, lazy_load=lazy_load)
  File "/home/travis/build/nipy/nibabel/venv/lib/python2.7/site-packages/nibabel/streamlines/tck.py", line 154, in load
    streamlines = ArraySequence(tck_reader)
  File "/home/travis/build/nipy/nibabel/venv/lib/python2.7/site-packages/nibabel/streamlines/array_sequence.py", line 93, in __init__
    self.extend(iterable)
  File "/home/travis/build/nipy/nibabel/venv/lib/python2.7/site-packages/nibabel/streamlines/array_sequence.py", line 239, in extend
    for e in elements:
  File "/home/travis/build/nipy/nibabel/venv/lib/python2.7/site-packages/nibabel/streamlines/tck.py", line 436, in _read
    pts.flags.writeable = True
ValueError: cannot set WRITEABLE flag to True of this array
ERROR: test_load_complex_file_in_big_endian (nibabel.streamlines.tests.test_trk.TestTRK)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/nipy/nibabel/venv/lib/python2.7/site-packages/nibabel/streamlines/tests/test_trk.py", line 194, in test_load_complex_file_in_big_endian
    'complex_trk_big_endian_fname', endian='>')
  File "/home/travis/build/nipy/nibabel/venv/lib/python2.7/site-packages/nibabel/streamlines/tests/test_trk.py", line 109, in trk_with_bytes
    trk_struct.flags.writeable = True
ValueError: cannot set WRITEABLE flag to True of this array
ERROR: test_big_offset_exts (nibabel.tests.test_analyze.TestAnalyzeImage)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/nipy/nibabel/venv/lib/python2.7/site-packages/nibabel/tests/test_analyze.py", line 809, in test_big_offset_exts
    assert_array_equal(arr, img_back.dataobj)
  File "/home/travis/build/nipy/nibabel/venv/lib/python2.7/site-packages/numpy/testing/_private/utils.py", line 873, in assert_array_equal
    verbose=verbose, header='Arrays are not equal')
  File "/home/travis/build/nipy/nibabel/venv/lib/python2.7/site-packages/numpy/testing/_private/utils.py", line 693, in assert_array_compare
    y = array(y, copy=False, subok=True)
  File "/home/travis/build/nipy/nibabel/venv/lib/python2.7/site-packages/nibabel/arrayproxy.py", line 356, in __array__
    raw_data = self.get_unscaled()
  File "/home/travis/build/nipy/nibabel/venv/lib/python2.7/site-packages/nibabel/arrayproxy.py", line 351, in get_unscaled
    mmap=self._mmap)
  File "/home/travis/build/nipy/nibabel/venv/lib/python2.7/site-packages/nibabel/volumeutils.py", line 543, in array_from_file
    arr.flags.writeable = True
ValueError: cannot set WRITEABLE flag to True of this array

We got the same error on DIPY project as you can see here

Why doesn't the readinto path get reached here that bypasses the readonly buffer?

@eric-wieser That error is only hit in the Python 2.7 tests, so it's due to readinto not existing in Py2.

I see readinto here, so it looks like it at least exists in python 2. What object are you passing that's missing that attribute?

@eric-wieser - Python 2.7 hits this path with Bzip2 files.

Can you take a dependency on the bz2file backport, @effigies?

Okay. I guess we should go ahead and merge #700 and cut a bug-fix release.