Skip to content

Commit 871a585

Browse files
authored
Merge pull request #964 from larsoner/float
FIX: NumPy float deprecation
2 parents 27d3b26 + 620dd6e commit 871a585

File tree

14 files changed

+43
-46
lines changed

14 files changed

+43
-46
lines changed

doc/source/old/ioimplementation.rst

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ By use case.
101101
>>> mod_data[0,0] = 99
102102
>>> np.all(img4.data = mod_data)
103103
True
104-
104+
105105
Prepare image for later writing
106106

107-
>>> img5 = Image(np.zeros(2,3,4))
107+
>>> img5 = Image(np.zeros(2,3,4))
108108
>>> fp, fname2 = tempfile.mkstemp('.nii')
109109
>>> img5.set_filespec(fname2)
110110
>>> # then do some things to the image
@@ -115,7 +115,7 @@ By use case.
115115
>>> from nibabel.ioimps import guessed_imp
116116
>>> fp, fname3 = tempfile.mkstemp('.nii')
117117
>>> ioimp = guessed_imp(fname3)
118-
>>> ioimp.set_data_dtype(np.float)
118+
>>> ioimp.set_data_dtype(np.float64)
119119
>>> ioimp.set_data_shape((2,3,4)) # set_data_shape method
120120
>>> slice_def = (slice(None), slice(None), 0)
121121
>>> ioimp.write_slice(data[slice_def], slice_def) # write_slice method
@@ -124,6 +124,3 @@ By use case.
124124
Traceback (most recent call last):
125125
...
126126
ImageIOError: data write is not contiguous
127-
128-
129-

nibabel/cifti2/parse_cifti2.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,28 +517,28 @@ def flush_chardata(self):
517517
# conversion to numpy array
518518
c = BytesIO(data.strip().encode('utf-8'))
519519
vertices = self.struct_state[-1]
520-
vertices.extend(np.loadtxt(c, dtype=np.int, ndmin=1))
520+
vertices.extend(np.loadtxt(c, dtype=int, ndmin=1))
521521
c.close()
522522

523523
elif self.write_to == 'VoxelIndices':
524524
# conversion to numpy array
525525
c = BytesIO(data.strip().encode('utf-8'))
526526
parent = self.struct_state[-1]
527-
parent.voxel_indices_ijk.extend(np.loadtxt(c, dtype=np.int).reshape(-1, 3))
527+
parent.voxel_indices_ijk.extend(np.loadtxt(c, dtype=int).reshape(-1, 3))
528528
c.close()
529529

530530
elif self.write_to == 'VertexIndices':
531531
# conversion to numpy array
532532
c = BytesIO(data.strip().encode('utf-8'))
533533
index = self.struct_state[-1]
534-
index.extend(np.loadtxt(c, dtype=np.int, ndmin=1))
534+
index.extend(np.loadtxt(c, dtype=int, ndmin=1))
535535
c.close()
536536

537537
elif self.write_to == 'TransformMatrix':
538538
# conversion to numpy array
539539
c = BytesIO(data.strip().encode('utf-8'))
540540
transform = self.struct_state[-1]
541-
transform.matrix = np.loadtxt(c, dtype=np.float)
541+
transform.matrix = np.loadtxt(c, dtype=np.float64)
542542
c.close()
543543

544544
elif self.write_to == 'Label':

nibabel/freesurfer/io.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def _fread3_many(fobj, n):
4949
An array of 3 byte int
5050
"""
5151
b1, b2, b3 = np.fromfile(fobj, ">u1", 3 * n).reshape(-1,
52-
3).astype(np.int).T
52+
3).astype(int).T
5353
return (b1 << 16) + (b2 << 8) + b3
5454

5555

@@ -148,14 +148,14 @@ def read_geometry(filepath, read_metadata=False, read_stamp=False):
148148
nvert = _fread3(fobj)
149149
nquad = _fread3(fobj)
150150
(fmt, div) = (">i2", 100.) if magic == QUAD_MAGIC else (">f4", 1.)
151-
coords = np.fromfile(fobj, fmt, nvert * 3).astype(np.float) / div
151+
coords = np.fromfile(fobj, fmt, nvert * 3).astype(np.float64) / div
152152
coords = coords.reshape(-1, 3)
153153
quads = _fread3_many(fobj, nquad * 4)
154154
quads = quads.reshape(nquad, 4)
155155
#
156156
# Face splitting follows
157157
#
158-
faces = np.zeros((2 * nquad, 3), dtype=np.int)
158+
faces = np.zeros((2 * nquad, 3), dtype=int)
159159
nface = 0
160160
for quad in quads:
161161
if (quad[0] % 2) == 0:
@@ -182,7 +182,7 @@ def read_geometry(filepath, read_metadata=False, read_stamp=False):
182182
else:
183183
raise ValueError("File does not appear to be a Freesurfer surface")
184184

185-
coords = coords.astype(np.float) # XXX: due to mayavi bug on mac 32bits
185+
coords = coords.astype(np.float64) # XXX: due to mayavi bug on mac 32bits
186186

187187
ret = (coords, faces)
188188
if read_metadata:
@@ -589,7 +589,7 @@ def read_label(filepath, read_scalars=False):
589589
Only returned if `read_scalars` is True. Array of scalar data for each
590590
vertex.
591591
"""
592-
label_array = np.loadtxt(filepath, dtype=np.int, skiprows=2, usecols=[0])
592+
label_array = np.loadtxt(filepath, dtype=int, skiprows=2, usecols=[0])
593593
if read_scalars:
594594
scalar_array = np.loadtxt(filepath, skiprows=2, usecols=[-1])
595595
return label_array, scalar_array

nibabel/freesurfer/tests/test_io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def test_write_morph_data():
157157
with pytest.raises(ValueError):
158158
write_morph_data('test.curv', np.zeros(shape), big_num)
159159
# Windows 32-bit overflows Python int
160-
if np.dtype(np.int) != np.dtype(np.int32):
160+
if np.dtype(int) != np.dtype(np.int32):
161161
with pytest.raises(ValueError):
162162
write_morph_data('test.curv', strided_scalar((big_num,)))
163163
for shape in bad_shapes:

nibabel/minc1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def _get_valid_range(self):
137137
if valid_range[0] < info.min or valid_range[1] > info.max:
138138
raise ValueError('Valid range outside input '
139139
'data type range')
140-
return np.asarray(valid_range, dtype=np.float)
140+
return np.asarray(valid_range, dtype=np.float64)
141141

142142
def _get_scalar(self, var):
143143
""" Get scalar value from NetCDF scalar """

nibabel/minc2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def _get_valid_range(self):
101101
if valid_range[0] < info.min or valid_range[1] > info.max:
102102
raise ValueError('Valid range outside input '
103103
'data type range')
104-
return np.asarray(valid_range, dtype=np.float)
104+
return np.asarray(valid_range, dtype=np.float64)
105105

106106
def _get_scalar(self, var):
107107
""" Get scalar value from HDF5 scalar """

nibabel/quaternions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
import math
2929
import numpy as np
3030

31-
MAX_FLOAT = np.maximum_sctype(np.float)
32-
FLOAT_EPS = np.finfo(np.float).eps
31+
MAX_FLOAT = np.maximum_sctype(float)
32+
FLOAT_EPS = np.finfo(float).eps
3333

3434

3535
def fillpositive(xyz, w2_thresh=None):
@@ -43,7 +43,7 @@ def fillpositive(xyz, w2_thresh=None):
4343
threshold to determine if w squared is really negative.
4444
If None (default) then w2_thresh set equal to
4545
``-np.finfo(xyz.dtype).eps``, if possible, otherwise
46-
``-np.finfo(np.float).eps``
46+
``-np.finfo(np.float64).eps``
4747
4848
Returns
4949
-------

nibabel/tests/test_arraywriters.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ def test_io_scaling():
468468

469469
def test_input_ranges():
470470
# Test we get good precision for a range of input data
471-
arr = np.arange(-500, 501, 10, dtype=np.float)
471+
arr = np.arange(-500, 501, 10, dtype=np.float64)
472472
bio = BytesIO()
473473
working_type = np.float32
474474
work_eps = np.finfo(working_type).eps
@@ -542,7 +542,7 @@ def test_nan2zero():
542542
def test_byte_orders():
543543
arr = np.arange(10, dtype=np.int32)
544544
# Test endian read/write of types not requiring scaling
545-
for tp in (np.uint64, np.float, np.complex):
545+
for tp in (np.uint64, np.float64, np.complex128):
546546
dt = np.dtype(tp)
547547
for code in '<>':
548548
ndt = dt.newbyteorder(code)
@@ -554,7 +554,7 @@ def test_byte_orders():
554554

555555

556556
def test_writers_roundtrip():
557-
ndt = np.dtype(np.float)
557+
ndt = np.dtype(np.float64)
558558
arr = np.arange(3, dtype=ndt)
559559
# intercept
560560
aw = SlopeInterArrayWriter(arr, ndt, calc_scale=False)
@@ -831,7 +831,7 @@ def test_finite_range_nan():
831831
([np.inf, 1], (1, 1)), # only look at finite values
832832
([-np.inf, 1], (1, 1)),
833833
([[], []], (np.inf, -np.inf)), # empty array
834-
(np.array([[-3, 0, 1], [2, -1, 4]], dtype=np.int), (-3, 4)),
834+
(np.array([[-3, 0, 1], [2, -1, 4]], dtype=int), (-3, 4)),
835835
(np.array([[1, 0, 1], [2, 3, 4]], dtype=np.uint), (0, 4)),
836836
([0., 1, 2, 3], (0, 3)),
837837
# Complex comparison works as if they are floats
@@ -859,7 +859,7 @@ def test_finite_range_nan():
859859
# Check float types work as complex
860860
in_arr = np.array(in_arr)
861861
if in_arr.dtype.kind == 'f':
862-
c_arr = in_arr.astype(np.complex)
862+
c_arr = in_arr.astype(np.complex128)
863863
try:
864864
aw = awt(c_arr, out_type, **kwargs)
865865
except WriterError:

nibabel/tests/test_euler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import pytest
1919
from numpy.testing import assert_array_equal, assert_array_almost_equal
2020

21-
FLOAT_EPS = np.finfo(np.float).eps
21+
FLOAT_EPS = np.finfo(np.float64).eps
2222

2323
# Example rotations """
2424
eg_rots = []

nibabel/tests/test_proxy_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666

6767
def _some_slicers(shape):
6868
ndim = len(shape)
69-
slicers = np.eye(ndim).astype(np.int).astype(object)
69+
slicers = np.eye(ndim).astype(int).astype(object)
7070
slicers[slicers == 0] = slice(None)
7171
for i in range(ndim):
7272
if i % 2:

0 commit comments

Comments
 (0)