Repository navigation
Fix the TimeSeriesReference that add_interval computes for a rate-based TimeSeries - #2275
Open
aaronkanzer wants to merge 1 commit into
Open
aaronkanzer wants to merge 1 commit into
aaronkanzer wants to merge 1 commit into
Conversation
aaronkanzer
force-pushed
the
fix/add-interval-rate-index
branch
from
October 24, 2026 12:36
281ad9e to
fcabe50
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TimeIntervals.add_interval(and soNWBFile.add_epoch) gives a differentTimeSeriesReferencefor a TimeSeries withstarting_timeandratethan for the same samples stored astimestamps. For the rate case the reference can start one sample beforestart_time. If the interval starts before the series, it is stored as a missing reference. If the interval runs past the end, the reference raisesIndexErrorwhen used.Observed (pynwb 4.2.0 and dev), rate vs timestamps:
For the last case,
ref.isvalid()raisesIndexError: 'idx_start + count' out of range for timeseries 'r'.Expected: both series give
(26, 25),(0, 10)and(90, 10).Cause: the rate branch of
__calculate_idx_countusesint((t - starting_time) * rate). That truncates instead of finding the first sample at or aftert, is sensitive to floating point error, and is never clipped to[0, num_samples]. The timestamps branch usesbisect_left, which has none of these problems.Fix: compute the rate-based index the way
bisect_leftwould on the sample timesstarting_time + i / rate(ceilwith a one-step correction for rounding), clipped to the number of samples. Adds tests that compare the rate and timestamps results, including intervals that extend past either end.