Skip to content

Commit 02e9ab8

Browse files
committed
Improvements to the "pretty" output in IPython
1 parent 345d339 commit 02e9ab8

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

neo/core/epoch.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
'''
77

88
from copy import deepcopy, copy
9+
from numbers import Number
910

1011
import numpy as np
1112
import quantities as pq
@@ -88,8 +89,10 @@ def __new__(cls, times=None, durations=None, labels=None, units=None, name=None,
8889
raise ValueError("Times array has more than 1 dimension")
8990
if isinstance(durations, (list, tuple)):
9091
durations = np.array(durations)
91-
if durations is None:
92+
elif durations is None:
9293
durations = np.array([]) * pq.s
94+
elif isinstance(durations, Number):
95+
durations = durations * np.ones(times.shape)
9396
elif durations.size != times.size:
9497
if durations.size == 1:
9598
durations = durations * np.ones_like(times.magnitude)
@@ -170,7 +173,14 @@ def __repr__(self):
170173
return '<Epoch: %s>' % ', '.join(objs)
171174

172175
def _repr_pretty_(self, pp, cycle):
173-
super()._repr_pretty_(pp, cycle)
176+
labels = ""
177+
if self._labels is not None:
178+
labels = " with labels"
179+
pp.text(f"{self.__class__.__name__} containing {self.size} epochs{labels}; "
180+
f"time units {self.units.dimensionality.string}; datatype {self.dtype} ")
181+
if self._has_repr_pretty_attrs_():
182+
pp.breakable()
183+
self._repr_pretty_attrs_(pp, cycle)
174184

175185
def rescale(self, units):
176186
'''

neo/core/event.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,14 @@ def __repr__(self):
148148
return '<Event: %s>' % ', '.join(objs)
149149

150150
def _repr_pretty_(self, pp, cycle):
151-
super()._repr_pretty_(pp, cycle)
151+
labels = ""
152+
if self._labels is not None:
153+
labels = " with labels"
154+
pp.text(f"{self.__class__.__name__} containing {self.size} events{labels}; "
155+
f"time units {self.units.dimensionality.string}; datatype {self.dtype} ")
156+
if self._has_repr_pretty_attrs_():
157+
pp.breakable()
158+
self._repr_pretty_attrs_(pp, cycle)
152159

153160
def rescale(self, units):
154161
'''

neo/core/spiketrain.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,21 @@ def __init__(self, times, t_stop, units=None, dtype=None, copy=True,
346346
array_annotations=array_annotations, **annotations)
347347

348348
def _repr_pretty_(self, pp, cycle):
349-
super()._repr_pretty_(pp, cycle)
349+
waveforms = ""
350+
if self.waveforms:
351+
waveforms = "with waveforms"
352+
pp.text(f"{self.__class__.__name__} containing {self.size} spikes{waveforms}; "
353+
f"units {self.units.dimensionality.string}; datatype {self.dtype} ")
354+
if self._has_repr_pretty_attrs_():
355+
pp.breakable()
356+
self._repr_pretty_attrs_(pp, cycle)
357+
358+
def _pp(line):
359+
pp.breakable()
360+
with pp.group(indent=1):
361+
pp.text(line)
362+
363+
_pp(f"time: {self.t_start} to {self.t_stop}")
350364

351365
def rescale(self, units):
352366
'''

0 commit comments

Comments
 (0)