-
Notifications
You must be signed in to change notification settings - Fork 267
Closed
Labels
Description
This test should pass
def test_save_from_generator(self):
tractogram = Tractogram(DATA['streamlines'],
affine_to_rasmm=np.eye(4))
# Just to create a generator
filtered = (s for s in tractogram.streamlines if True)
lazy_tractogram = LazyTractogram(lambda: filtered,
affine_to_rasmm=np.eye(4))
for ext, _ in FORMATS.items():
with InTemporaryDirectory():
filename = 'streamlines' + ext
nib.streamlines.save(lazy_tractogram, filename)
tfile = nib.streamlines.load(filename, lazy_load=False)
assert_tractogram_equal(tfile.tractogram, tractogram)
The problem comes from
first_item = next(iter(self.tractogram))
...
for t in tractogram:
When self.tractogram
is a generator, first_item
is not in the generator anymore.
I took 10 minutes to fix it but I couldn't find a clean way to do it. A simple itertools.chain([first_item], tractogram)
is not enough :)