Skip to content

Commit 693f1a1

Browse files
authored
Merge branch 'master' into small_changes_to_intan
2 parents 32d2685 + 9892c95 commit 693f1a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1525
-832
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ cover
5858
.directory
5959
.gdb_history
6060
.DS_Store?
61+
.DS_Store
6162
ehthumbs.db
6263
Icon?
6364
Thumbs.db

neo/core/analogsignal.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,7 @@ def __repr__(self):
294294
"""
295295
Returns a string representing the :class:`AnalogSignal`.
296296
"""
297-
return "<%s(%s, [%s, %s], sampling rate: %s)>" % (
298-
self.__class__.__name__,
299-
super().__repr__(),
300-
self.t_start,
301-
self.t_stop,
302-
self.sampling_rate,
303-
)
297+
return f"<{self.__class__.__name__}({super().__repr__()}, [{self.t_start}, {self.t_stop}], sampling rate: {self.sampling_rate})>"
304298

305299
def __getitem__(self, i):
306300
"""
@@ -324,7 +318,7 @@ def __getitem__(self, i):
324318
raise NotImplementedError("Arrays not yet supported") # in the general case, would need to return
325319
# IrregularlySampledSignal(Array)
326320
else:
327-
raise TypeError("%s not supported" % type(j))
321+
raise TypeError(f"{type(j)} not supported")
328322
if isinstance(k, (int, np.integer)):
329323
obj = obj.reshape(-1, 1)
330324
elif k is None:
@@ -473,7 +467,7 @@ def _check_consistency(self, other):
473467
if isinstance(other, AnalogSignal):
474468
for attr in "t_start", "sampling_rate":
475469
if getattr(self, attr) != getattr(other, attr):
476-
raise ValueError("Inconsistent values of %s" % attr) # how to handle name and annotations?
470+
raise ValueError(f"Inconsistent values of {attr}") # how to handle name and annotations?
477471

478472
def _repr_pretty_(self, pp, cycle):
479473
"""

neo/core/basesignal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def merge(self, other):
237237
for attr in self._necessary_attrs:
238238
if "signal" != attr[0]:
239239
if getattr(self, attr[0], None) != getattr(other, attr[0], None):
240-
raise MergeError("Cannot merge these two signals as the %s differ." % attr[0])
240+
raise MergeError(f"Cannot merge these two signals as the {attr[0]} differ.")
241241

242242
if self.segment != other.segment:
243243
raise MergeError("Cannot merge these two signals as they belong to different segments.")

neo/core/container.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,6 @@ def _repr_pretty_(self, pp, cycle):
577577
pp.text(f"# {container} (N={objs})")
578578
for i, obj in enumerate(objs):
579579
pp.breakable()
580-
pp.text("%s: " % i)
580+
pp.text(f"{i}: ")
581581
with pp.indent(3):
582582
pp.pretty(obj)

neo/core/dataobject.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ def __setitem__(self, key, value):
400400
def update(self, *args, **kwargs):
401401
if args:
402402
if len(args) > 1:
403-
raise TypeError("update expected at most 1 arguments, " "got %d" % len(args))
403+
raise TypeError("update expected at most 1 arguments, " f"got {len(args)}")
404404
other = dict(args[0])
405405
for key in other:
406406
self[key] = other[key]

neo/core/epoch.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def __new__(
155155
# this approach is much faster than comparing the
156156
# reference dimensionality
157157
if len(dim) != 1 or list(dim.values())[0] != 1 or not isinstance(list(dim.keys())[0], pq.UnitTime):
158-
ValueError("Unit %s has dimensions %s, not [time]" % (units, dim.simplified))
158+
ValueError(f"Unit {units} has dimensions {dim.simplified}, not [time]")
159159

160160
obj = pq.Quantity.__new__(cls, times, units=dim)
161161
obj._labels = labels
@@ -227,8 +227,7 @@ def __repr__(self):
227227
"""
228228

229229
objs = [
230-
"%s@%s for %s" % (label, str(time), str(dur))
231-
for label, time, dur in zip(self.labels, self.times, self.durations)
230+
f"{label}@{str(time)} for {str(dur)}" for label, time, dur in zip(self.labels, self.times, self.durations)
232231
]
233232
return "<Epoch: %s>" % ", ".join(objs)
234233

neo/core/event.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def __repr__(self):
194194
Returns a string representing the :class:`Event`.
195195
"""
196196

197-
objs = ["%s@%s" % (label, str(time)) for label, time in zip(self.labels, self.times)]
197+
objs = [f"{label}@{str(time)}" for label, time in zip(self.labels, self.times)]
198198
return "<Event: %s>" % ", ".join(objs)
199199

200200
def _repr_pretty_(self, pp, cycle):

neo/core/imagesequence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def _check_consistency(self, other):
227227
if isinstance(other, ImageSequence):
228228
for attr in ("sampling_rate", "spatial_scale", "t_start"):
229229
if getattr(self, attr) != getattr(other, attr):
230-
raise ValueError("Inconsistent values of %s" % attr)
230+
raise ValueError(f"Inconsistent values of {attr}")
231231

232232
# t_start attribute is handled as a property so type checking can be done
233233
@property

neo/core/irregularlysampledsignal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def __getitem__(self, i):
272272
elif isinstance(j, np.ndarray):
273273
raise NotImplementedError("Arrays not yet supported")
274274
else:
275-
raise TypeError("%s not supported" % type(j))
275+
raise TypeError(f"{type(j)} not supported")
276276
if isinstance(k, (int, np.integer)):
277277
obj = obj.reshape(-1, 1)
278278
obj.array_annotations = deepcopy(self.array_annotations_at_index(k))
@@ -600,7 +600,7 @@ def concatenate(self, other, allow_overlap=False):
600600
for attr in self._necessary_attrs:
601601
if not (attr[0] in ["signal", "times", "t_start", "t_stop", "times"]):
602602
if getattr(self, attr[0], None) != getattr(other, attr[0], None):
603-
raise MergeError("Cannot concatenate these two signals as the %s differ." % attr[0])
603+
raise MergeError(f"Cannot concatenate these two signals as the {attr[0]} differ.")
604604

605605
if hasattr(self, "lazy_shape"):
606606
if hasattr(other, "lazy_shape"):

neo/core/objectlist.py

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(self, allowed_contents, parent=None):
2121
for item in allowed_contents:
2222
assert issubclass(item, BaseNeo)
2323
self.allowed_contents = tuple(allowed_contents)
24-
self.contents = []
24+
self._items = []
2525
self.parent = parent
2626

2727
def _handle_append(self, obj):
@@ -32,6 +32,10 @@ def _handle_append(self, obj):
3232
)
3333
):
3434
raise TypeError(f"Object is a {type(obj)}. It should be one of {self.allowed_contents}.")
35+
36+
if self._contains(obj):
37+
raise ValueError("Cannot add this object because it is already contained within the list")
38+
3539
# set the child-parent relationship
3640
if self.parent:
3741
relationship_name = self.parent.__class__.__name__.lower()
@@ -42,76 +46,83 @@ def _handle_append(self, obj):
4246
# use weakref here? - see https://github.com/NeuralEnsemble/python-neo/issues/684
4347
setattr(obj, relationship_name, self.parent)
4448

49+
def _contains(self, obj):
50+
if self._items is None:
51+
obj_ids = []
52+
else:
53+
obj_ids = [id(item) for item in self._items]
54+
return id(obj) in obj_ids
55+
4556
def __str__(self):
46-
return str(self.contents)
57+
return str(self._items)
4758

4859
def __repr__(self):
49-
return repr(self.contents)
60+
return repr(self._items)
5061

5162
def __add__(self, objects):
5263
# todo: decision: return a list, or a new DataObjectList?
5364
if isinstance(objects, ObjectList):
54-
return self.contents + objects.contents
65+
return self._items + objects._items
5566
else:
56-
return self.contents + objects
67+
return self._items + objects
5768

5869
def __radd__(self, objects):
5970
if isinstance(objects, ObjectList):
60-
return objects.contents + self.contents
71+
return objects._items + self._items
6172
else:
62-
return objects + self.contents
73+
return objects + self._items
6374

6475
def __contains__(self, key):
65-
return key in self.contents
76+
return key in self._items
6677

6778
def __iadd__(self, objects):
6879
for obj in objects:
6980
self._handle_append(obj)
70-
self.contents.extend(objects)
81+
self._items.extend(objects)
7182
return self
7283

7384
def __iter__(self):
74-
return iter(self.contents)
85+
return iter(self._items)
7586

7687
def __getitem__(self, i):
77-
return self.contents[i]
88+
return self._items[i]
7889

7990
def __len__(self):
80-
return len(self.contents)
91+
return len(self._items)
8192

8293
def __setitem__(self, key, value):
83-
self.contents[key] = value
94+
self._items[key] = value
8495

8596
def append(self, obj):
8697
self._handle_append(obj)
87-
self.contents.append(obj)
98+
self._items.append(obj)
8899

89100
def extend(self, objects):
90101
for obj in objects:
91102
self._handle_append(obj)
92-
self.contents.extend(objects)
103+
self._items.extend(objects)
93104

94105
def clear(self):
95-
self.contents = []
106+
self._items = []
96107

97108
def count(self, value):
98-
return self.contents.count(value)
109+
return self._items.count(value)
99110

100111
def index(self, value, start=0, stop=sys.maxsize):
101-
return self.contents.index(value, start, stop)
112+
return self._items.index(value, start, stop)
102113

103114
def insert(self, index, obj):
104115
self._handle_append(obj)
105-
self.contents.insert(index, obj)
116+
self._items.insert(index, obj)
106117

107118
def pop(self, index=-1):
108-
return self.contents.pop(index)
119+
return self._items.pop(index)
109120

110121
def remove(self, value):
111-
return self.contents.remove(value)
122+
return self._items.remove(value)
112123

113124
def reverse(self):
114-
raise self.contents.reverse()
125+
raise self._items.reverse()
115126

116127
def sort(self, *args, key=None, reverse=False):
117-
self.contents.sort(*args, key=key, reverse=reverse)
128+
self._items.sort(*args, key=key, reverse=reverse)

0 commit comments

Comments
 (0)