Skip to content

Prevent empty seg in random_segment which causes tests to fail stochastically - #1666

Merged
apdavison merged 2 commits into
NeuralEnsemble:masterfrom
zm711:randomsegstochastic
Mar 25, 2025
Merged

apdavison merged 2 commits into
NeuralEnsemble:masterfrom
zm711:randomsegstochastic

Conversation

@zm711

@zm711 zm711 commented Mar 24, 2025 •

Copy link
Copy Markdown
Contributor

Basically we have stochastic failures in this test

def test_times(self):
for seg in self.segments:
# calculate target values for t_start and t_stop
t_starts, t_stops = [], []
for children in [seg.analogsignals, seg.epochs, seg.events, seg.irregularlysampledsignals, seg.spiketrains]:
for child in children:
if hasattr(child, "t_start"):
t_starts.append(child.t_start)
if hasattr(child, "t_stop"):
t_stops.append(child.t_stop)
if hasattr(child, "time"):
t_starts.append(child.time)
t_stops.append(child.time)
if hasattr(child, "times"):
t_starts.append(child.times[0])
t_stops.append(child.times[-1])
targ_t_start = min(t_starts)
targ_t_stop = max(t_stops)
self.assertEqual(seg.t_start, targ_t_start)
self.assertEqual(seg.t_stop, targ_t_stop)

because currently we sometimes generate a completely empty segment with nothing in it so the list of t_starts is empty which causes the min function to fail. This makes us have to re-run the test CI to get a result. Instead I made the function recursive such that each segment needs to have at least one of the types of children objects for testing purposes (to be clear it just needs one so if the n_child is 0 for all types of children then it fails which is what causes the test to stochastically fail).

The other option would be to change the test to accept the fact we have an empty segment. So let me know what you think @apdavison !

@apdavison

Copy link
Copy Markdown
Member

I think this is a good solution.

@apdavison
apdavison merged commit 07fa5b3 into NeuralEnsemble:master Mar 25, 2025
@zm711
zm711 deleted the randomsegstochastic branch March 25, 2025 10:21
@zm711 zm711 added this to the 0.14.1 milestone Mar 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants