Skip to content

Commit a6c1435

Browse files
authored
Merge pull request #1010 from JuliaSprenger/fix/warnings
fix failing tests and warnings
2 parents ca35743 + 43a4347 commit a6c1435

20 files changed

+80
-102
lines changed

neo/core/spiketrain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def normalize_times_array(times, units=None, dtype=None, copy=True):
126126
"""
127127
if dtype is None:
128128
if not hasattr(times, 'dtype'):
129-
dtype = np.float
129+
dtype = float
130130
if units is None:
131131
# No keyword units, so get from `times`
132132
try:

neo/core/view.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __init__(self, obj, index, name=None, description=None, file_origin=None,
5555
self.index = np.array(index)
5656
if len(self.index.shape) != 1:
5757
raise ValueError("index must be a 1D array")
58-
if self.index.dtype == np.bool: # convert boolean mask to integer index
58+
if self.index.dtype == bool: # convert boolean mask to integer index
5959
if self.index.size != self.obj.shape[-1]:
6060
raise ValueError("index size does not match number of channels in signal")
6161
self.index, = np.nonzero(self.index)

neo/io/asciisignalio.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -199,29 +199,29 @@ def read_segment(self, lazy=False):
199199
if len(sig.shape) == 1:
200200
sig = sig[:, np.newaxis]
201201
elif self.method == 'csv':
202-
with open(self.filename, 'rU') as fp:
202+
with open(self.filename, newline=None) as fp:
203203
tab = [l for l in csv.reader(fp, delimiter=self.delimiter)]
204204
tab = tab[self.skiprows:]
205205
sig = np.array(tab, dtype='f')
206206
if self.usecols is not None:
207207
mask = np.array(self.usecols)
208208
sig = sig[:, mask]
209209
elif self.method == 'homemade':
210-
fid = open(self.filename, 'rU')
211-
for l in range(self.skiprows):
212-
fid.readline()
213-
tab = []
214-
for line in fid.readlines():
215-
line = line.replace('\r', '')
216-
line = line.replace('\n', '')
217-
parts = line.split(self.delimiter)
218-
while '' in parts:
219-
parts.remove('')
220-
tab.append(parts)
221-
sig = np.array(tab, dtype='f')
222-
if self.usecols is not None:
223-
mask = np.array(self.usecols)
224-
sig = sig[:, mask]
210+
with open(self.filename, 'r', newline=None) as fid:
211+
for _ in range(self.skiprows):
212+
fid.readline()
213+
tab = []
214+
for line in fid.readlines():
215+
line = line.replace('\r', '')
216+
line = line.replace('\n', '')
217+
parts = line.split(self.delimiter)
218+
while '' in parts:
219+
parts.remove('')
220+
tab.append(parts)
221+
sig = np.array(tab, dtype='f')
222+
if self.usecols is not None:
223+
mask = np.array(self.usecols)
224+
sig = sig[:, mask]
225225
else:
226226
sig = self.method(self.filename, self.usecols)
227227
if not isinstance(sig, np.ndarray):

neo/io/asciispiketrainio.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,21 @@ def read_segment(self,
9191

9292
seg = Segment(file_origin=os.path.basename(self.filename))
9393

94-
f = open(self.filename, 'Ur')
95-
for i, line in enumerate(f):
96-
alldata = line[:-1].split(delimiter)
97-
if alldata[-1] == '':
98-
alldata = alldata[:-1]
99-
if alldata[0] == '':
100-
alldata = alldata[1:]
94+
with open(self.filename, 'r', newline=None) as f:
95+
for i, line in enumerate(f):
96+
alldata = line[:-1].split(delimiter)
97+
if alldata[-1] == '':
98+
alldata = alldata[:-1]
99+
if alldata[0] == '':
100+
alldata = alldata[1:]
101101

102-
spike_times = np.array(alldata).astype('f')
103-
t_stop = spike_times.max() * unit
102+
spike_times = np.array(alldata).astype('f')
103+
t_stop = spike_times.max() * unit
104104

105-
sptr = SpikeTrain(spike_times * unit, t_start=t_start, t_stop=t_stop)
105+
sptr = SpikeTrain(spike_times * unit, t_start=t_start, t_stop=t_stop)
106106

107-
sptr.annotate(channel_index=i)
108-
seg.spiketrains.append(sptr)
109-
f.close()
107+
sptr.annotate(channel_index=i)
108+
seg.spiketrains.append(sptr)
110109

111110
seg.create_many_to_one_relationship()
112111
return seg

neo/io/brainwaredamio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def _read_segment(self, fobject):
193193
name = np.fromfile(fobject, dtype=np.uint8, count=numchars)
194194

195195
# exclude invalid characters
196-
name = str(name[name >= 32].view('c').tostring())
196+
name = str(name[name >= 32].view('c').tobytes())
197197

198198
# add the name to the list of names
199199
paramnames.append(name)

neo/io/elphyio.py

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

7474
# python commons:
7575
from datetime import datetime
76-
from fractions import gcd
76+
from math import gcd
7777
from os import path
7878
import re
7979
import struct

neo/io/tiffio.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,15 @@ def natural_sort(l):
102102
file_name_list = natural_sort(file_name_list)
103103
list_data_image = []
104104
for file_name in file_name_list:
105-
list_data_image.append(
106-
np.array(Image.open(self.filename + "/" + file_name), dtype=np.float32))
105+
data = np.array(Image.open(self.filename + "/" + file_name)).astype(np.float32)
106+
list_data_image.append(data)
107107
list_data_image = np.array(list_data_image)
108108
if len(list_data_image.shape) == 4:
109109
list_data_image = []
110110
for file_name in file_name_list:
111-
list_data_image.append(
112-
np.array(Image.open(self.filename + "/" + file_name).convert('L'), dtype=np.float32))
111+
image = Image.open(self.filename + "/" + file_name).convert('L')
112+
data = np.array(image).astype(np.float32)
113+
list_data_image.append(data)
113114

114115
print("read block")
115116
image_sequence = ImageSequence(np.stack(list_data_image),

neo/rawio/bci2000rawio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def _get_event_timestamps(self, block_index, seg_index, event_channel_index, t_s
175175
# label must a dtype ='U'
176176
ts, dur, labels = self._event_arrays_list[event_channel_index]
177177
# seg_t_start = self._segment_t_start(block_index, seg_index)
178-
keep = np.ones(ts.shape, dtype=np.bool)
178+
keep = np.ones(ts.shape, dtype=bool)
179179
if t_start is not None:
180180
keep = np.logical_and(keep, ts >= t_start)
181181
if t_stop is not None:

neo/rawio/micromedrawio.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
77
Author: Samuel Garcia
88
"""
9-
# from __future__ import unicode_literals is not compatible with numpy.dtype both py2 py3
10-
119

1210
from .baserawio import (BaseRawIO, _signal_channel_dtype, _signal_stream_dtype,
1311
_spike_channel_dtype, _event_channel_dtype)

neo/test/coretest/test_base.py

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ def setUp(self):
769769

770770
def test_numpy_array_int(self):
771771
'''test to make sure int type numpy arrays are accepted'''
772-
value = np.array([1, 2, 3, 4, 5], dtype=np.int)
772+
value = np.array([1, 2, 3, 4, 5], dtype=int)
773773
self.base.annotate(data=value)
774774
result = {'data': value}
775775
self.assertDictEqual(result, self.base.annotations)
@@ -858,13 +858,6 @@ def test_numpy_array_float(self):
858858
result = {'data': value}
859859
self.assertDictEqual(result, self.base.annotations)
860860

861-
def test_numpy_array_floating(self):
862-
'''test to make sure floating type numpy arrays are accepted'''
863-
value = np.array([1, 2, 3, 4, 5], dtype=np.floating)
864-
self.base.annotate(data=value)
865-
result = {'data': value}
866-
self.assertDictEqual(result, self.base.annotations)
867-
868861
def test_numpy_array_double(self):
869862
'''test to make sure double type numpy arrays are accepted'''
870863
value = np.array([1, 2, 3, 4, 5], dtype=np.double)
@@ -903,7 +896,7 @@ def test_numpy_array_float128(self):
903896

904897
def test_numpy_array_complex(self):
905898
'''test to make sure complex type numpy arrays are accepted'''
906-
value = np.array([1, 2, 3, 4, 5], dtype=np.complex)
899+
value = np.array([1, 2, 3, 4, 5], complex)
907900
self.base.annotate(data=value)
908901
result = {'data': value}
909902
self.assertDictEqual(result, self.base.annotations)
@@ -933,14 +926,14 @@ def test_numpy_scalar_complex256(self):
933926

934927
def test_numpy_array_bool(self):
935928
'''test to make sure bool type numpy arrays are accepted'''
936-
value = np.array([1, 2, 3, 4, 5], dtype=np.bool)
929+
value = np.array([1, 2, 3, 4, 5], dtype=bool)
937930
self.base.annotate(data=value)
938931
result = {'data': value}
939932
self.assertDictEqual(result, self.base.annotations)
940933

941934
def test_numpy_array_str(self):
942935
'''test to make sure str type numpy arrays are accepted'''
943-
value = np.array([1, 2, 3, 4, 5], dtype=np.str)
936+
value = np.array([1, 2, 3, 4, 5], dtype=str)
944937
self.base.annotate(data=value)
945938
result = {'data': value}
946939
self.assertDictEqual(result, self.base.annotations)
@@ -964,7 +957,7 @@ def setUp(self):
964957

965958
def test_numpy_scalar_int(self):
966959
'''test to make sure int type numpy scalars are accepted'''
967-
value = np.array(99, dtype=np.int)
960+
value = np.array(99, dtype=int)
968961
self.base.annotate(data=value)
969962
result = {'data': value}
970963
self.assertDictEqual(result, self.base.annotations)
@@ -1053,13 +1046,6 @@ def test_numpy_scalar_float(self):
10531046
result = {'data': value}
10541047
self.assertDictEqual(result, self.base.annotations)
10551048

1056-
def test_numpy_scalar_floating(self):
1057-
'''test to make sure floating type numpy scalars are accepted'''
1058-
value = np.array(99, dtype=np.floating)
1059-
self.base.annotate(data=value)
1060-
result = {'data': value}
1061-
self.assertDictEqual(result, self.base.annotations)
1062-
10631049
def test_numpy_scalar_double(self):
10641050
'''test to make sure double type numpy scalars are accepted'''
10651051
value = np.array(99, dtype=np.double)
@@ -1098,7 +1084,7 @@ def test_numpy_scalar_float128(self):
10981084

10991085
def test_numpy_scalar_complex(self):
11001086
'''test to make sure complex type numpy scalars are accepted'''
1101-
value = np.array(99, dtype=np.complex)
1087+
value = np.array(99, dtype=complex)
11021088
self.base.annotate(data=value)
11031089
result = {'data': value}
11041090
self.assertDictEqual(result, self.base.annotations)
@@ -1127,14 +1113,14 @@ def test_numpy_scalar_complex256(self):
11271113

11281114
def test_numpy_scalar_bool(self):
11291115
'''test to make sure bool type numpy scalars are rejected'''
1130-
value = np.array(99, dtype=np.bool)
1116+
value = np.array(99, dtype=bool)
11311117
self.base.annotate(data=value)
11321118
result = {'data': value}
11331119
self.assertDictEqual(result, self.base.annotations)
11341120

11351121
def test_numpy_array_str(self):
11361122
'''test to make sure str type numpy scalars are accepted'''
1137-
value = np.array(99, dtype=np.str)
1123+
value = np.array(99, dtype=str)
11381124
self.base.annotate(data=value)
11391125
result = {'data': value}
11401126
self.assertDictEqual(result, self.base.annotations)
@@ -1159,7 +1145,7 @@ def setUp(self):
11591145

11601146
def test_quantities_array_int(self):
11611147
'''test to make sure int type quantites arrays are accepted'''
1162-
value = pq.Quantity([1, 2, 3, 4, 5], dtype=np.int, units=pq.s)
1148+
value = pq.Quantity([1, 2, 3, 4, 5], dtype=int, units=pq.s)
11631149
self.base.annotate(data=value)
11641150
result = {'data': value}
11651151
self.assertDictEqual(result, self.base.annotations)
@@ -1180,7 +1166,7 @@ def test_quantities_array_float(self):
11801166

11811167
def test_quantities_array_str(self):
11821168
'''test to make sure str type quantites arrays are accepted'''
1183-
value = pq.Quantity([1, 2, 3, 4, 5], dtype=np.str, units=pq.meter)
1169+
value = pq.Quantity([1, 2, 3, 4, 5], dtype=str, units=pq.meter)
11841170
self.base.annotate(data=value)
11851171
result = {'data': value}
11861172
self.assertDictEqual(result, self.base.annotations)
@@ -1198,7 +1184,7 @@ def setUp(self):
11981184

11991185
def test_quantities_scalar_int(self):
12001186
'''test to make sure int type quantites scalars are accepted'''
1201-
value = pq.Quantity(99, dtype=np.int, units=pq.s)
1187+
value = pq.Quantity(99, dtype=int, units=pq.s)
12021188
self.base.annotate(data=value)
12031189
result = {'data': value}
12041190
self.assertDictEqual(result, self.base.annotations)
@@ -1219,7 +1205,7 @@ def test_quantities_scalar_float(self):
12191205

12201206
def test_quantities_scalar_str(self):
12211207
'''test to make sure str type quantites scalars are accepted'''
1222-
value = pq.Quantity(99, dtype=np.str, units=pq.meter)
1208+
value = pq.Quantity(99, dtype=str, units=pq.meter)
12231209
self.base.annotate(data=value)
12241210
result = {'data': value}
12251211
self.assertDictEqual(result, self.base.annotations)

0 commit comments

Comments
 (0)