Skip to content

Commit 7fc30cb

Browse files
Merge pull request #1170 from apdavison/improved-pretty
Improved pretty
2 parents 49581af + 4650f48 commit 7fc30cb

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

neo/core/epoch.py

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

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

180187
def rescale(self, units):
181188
'''

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)