Skip to content

Commit d5cd2ad

Browse files
committed
RuntimeError if index != np.round(index) to asses
1 parent 025c211 commit d5cd2ad

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

mne/utils/mixin.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -520,23 +520,27 @@ def time_as_index(self, times, use_rounding=None):
520520
"""
521521
from ..source_estimate import _BaseSourceEstimate
522522

523+
if isinstance(self, _BaseSourceEstimate):
524+
sfreq = 1.0 / self.tstep
525+
else:
526+
sfreq = self.info["sfreq"]
527+
index = (np.atleast_1d(times) - self.times[0]) * sfreq
528+
523529
if use_rounding is None:
524530
# Turned off temporarily to see the impact of the change without
525-
# crashing on a FutureWarning
531+
# crashing on a FutureWarning. Only crash, explicitely, if the
532+
# values with and without rounding are different.
526533
#
527534
# warn(
528535
# "The default of use_rounding=False is being changed to True "
529536
# "in a future release. Pass use_rounding=True or "
530537
# "use_rounding=False explicitly to silence this warning.",
531538
# FutureWarning,
532539
# )
540+
if index != np.round(index):
541+
raise RuntimeError(f"This would have returned a different value: {index=}, different from {np.round(index)=}.")
533542
use_rounding = True
534543

535-
if isinstance(self, _BaseSourceEstimate):
536-
sfreq = 1.0 / self.tstep
537-
else:
538-
sfreq = self.info["sfreq"]
539-
index = (np.atleast_1d(times) - self.times[0]) * sfreq
540544
if use_rounding:
541545
index = np.round(index)
542546
return index.astype(int)

0 commit comments

Comments
 (0)