jjhelmus / nmrglue

A module for working with NMR data in Python
BSD 3-Clause "New" or "Revised" License
211 stars 86 forks source link

Intergers not floats should be used for indexing and slicing arrays #60

Closed jjhelmus closed 7 years ago

jjhelmus commented 7 years ago

In various places in nmrglue a float type is used to slice or index a NumPy array. This was allowed in many versions of NumPy but in NumPy 1.12 this behavior is not allowed, integers must be used for indexing and slicing.

One concrete example of this is trying to read a simple NMRPipe file:

>>> import nmrglue as ng
>>> dic, data = ng.pipe.read('test.fid')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/nmrglue/fileio/pipe.py", line 531, in read
    return read_2D(filename)
  File "/usr/local/lib/python2.7/dist-packages/nmrglue/fileio/pipe.py", line 625, in read_2D
    data = unappend_data(data)
  File "/usr/local/lib/python2.7/dist-packages/nmrglue/fileio/pipe.py", line 1497, in unappend_data
    return np.array(data[..., :h] + data[..., h:] * 1.j, dtype="complex64")
TypeError: slice indices must be integers or None or have an __index__ method
jjhelmus commented 7 years ago

After looking into this further this seems to be a repeat of issue #51 which was fixed in #52. This has not made it into a nmrglue release so to pick up these fixes nmrglue must be installed from source.