|
6 | 6 | ''' |
7 | 7 |
|
8 | 8 | from copy import deepcopy, copy |
| 9 | +from numbers import Number |
9 | 10 |
|
10 | 11 | import numpy as np |
11 | 12 | import quantities as pq |
@@ -88,8 +89,10 @@ def __new__(cls, times=None, durations=None, labels=None, units=None, name=None, |
88 | 89 | raise ValueError("Times array has more than 1 dimension") |
89 | 90 | if isinstance(durations, (list, tuple)): |
90 | 91 | durations = np.array(durations) |
91 | | - if durations is None: |
| 92 | + elif durations is None: |
92 | 93 | durations = np.array([]) * pq.s |
| 94 | + elif isinstance(durations, Number): |
| 95 | + durations = durations * np.ones(times.shape) |
93 | 96 | elif durations.size != times.size: |
94 | 97 | if durations.size == 1: |
95 | 98 | durations = durations * np.ones_like(times.magnitude) |
@@ -170,7 +173,14 @@ def __repr__(self): |
170 | 173 | return '<Epoch: %s>' % ', '.join(objs) |
171 | 174 |
|
172 | 175 | 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) |
174 | 184 |
|
175 | 185 | def rescale(self, units): |
176 | 186 | ''' |
|
0 commit comments