… now you can’t.
I recently updated to the latest version of NumPy (1.12.1), and today I discovered that some of my spreadsheets using NumPy arrays (via xlwings) were returning errors like:
IndexError: only integers, slices (`:`), ellipsis (`…`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
The problem was that using floats to index NumPy arrays previously generated a warning, but now generates an error:
DeprecationWarning to error
•Indexing with floats raises IndexError, e.g., a[0, 0.0].
•Indexing with non-integer array_like raises IndexError, e.g., a[‘1’, ‘2’]
•Indexing with multiple ellipsis raises IndexError, e.g., a[…, …].
•Non-integers used as index values raise TypeError, e.g., in reshape, take, and specifying reduce axis
You might ask, why use floats to index an array in the first place? The reason is that if a range is copied from Excel to Python then by default all the values are passed as float64. The array could be converted to all integers, but if the values are mixed integers and floats (such as an array of node numbers and coordinates) that won’t work. In previous versions the values to be used as array indices could just be left as floats, but now it is necessary to convert them to integers before using them as index values.
I will be working through my Python code posted here and update as required, but if you come across an IndexError anywhere, please let me know.