Skip to content

Commit fa7a3a2

Browse files
matthew-brettMarcCote
authored andcommitted
RF: use self.__class__ for easier subclassing
Instead of hard-coding the class name, use ``self.__class__``. If someone wants to subclass ArraySequence, they do not have to overwrite the methods hard-coding the class name.
1 parent a6e5026 commit fa7a3a2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

nibabel/streamlines/array_sequence.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def extend(self, elements):
145145
this :class:`ArraySequence` except for the first dimension.
146146
"""
147147
if not is_array_sequence(elements):
148-
self.extend(ArraySequence(elements))
148+
self.extend(self.__class__(elements))
149149
return
150150

151151
if len(elements) == 0:
@@ -184,7 +184,7 @@ def copy(self):
184184
less memory. For example, if the array sequence being copied is the
185185
result of a slicing operation on an array sequence.
186186
"""
187-
seq = ArraySequence()
187+
seq = self.__class__()
188188
total_lengths = np.sum(self._lengths)
189189
seq._data = np.empty((total_lengths,) + self._data.shape[1:],
190190
dtype=self._data.dtype)
@@ -226,7 +226,7 @@ def __getitem__(self, idx):
226226
return self._data[start:start + self._lengths[idx]]
227227

228228
elif isinstance(idx, (slice, list)):
229-
seq = ArraySequence()
229+
seq = self.__class__()
230230
seq._data = self._data
231231
seq._offsets = self._offsets[idx]
232232
seq._lengths = self._lengths[idx]
@@ -236,7 +236,7 @@ def __getitem__(self, idx):
236236
elif (isinstance(idx, np.ndarray) and
237237
(np.issubdtype(idx.dtype, np.integer) or
238238
np.issubdtype(idx.dtype, np.bool))):
239-
seq = ArraySequence()
239+
seq = self.__class__()
240240
seq._data = self._data
241241
seq._offsets = self._offsets[idx]
242242
seq._lengths = self._lengths[idx]

0 commit comments

Comments
 (0)