-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix: Rounding error in get_data with tmin/tmax #13635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
2f91fdd
d459384
3995e9b
a7746ad
fbb02fe
6831f80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -1595,6 +1595,35 @@ def _handle_empty(self, on_empty, meth): | |||
| ) | ||||
| _on_missing(on_empty, msg, error_klass=RuntimeError) | ||||
|
|
||||
| def _handle_tmin_tmax(self, tmin, tmax): | ||||
| """Convert seconds to index into data.""" | ||||
| _validate_type( | ||||
| tmin, | ||||
| types=("numeric", None), | ||||
| item_name="tmin", | ||||
| type_name="int, float, None", | ||||
| ) | ||||
| _validate_type( | ||||
| tmax, | ||||
| types=("numeric", None), | ||||
| item_name="tmax", | ||||
| type_name="int, float, None", | ||||
| ) | ||||
|
|
||||
| # handle tmin/tmax as start and stop indices into data array | ||||
| n_times = self.times.size | ||||
| # QUI c'è la fix specifica per le Epochs | ||||
|
||||
| # QUI c'è la fix specifica per le Epochs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about that! I left a debug comment by mistake. I will remove it in the next commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will need some discussion. When use_rounding was introduced, it was determined that we shouldn't change the default:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding a new private method to Epochs that has the same name as an existing utility function is not the right way to go about this. It duplicates code and introduces the possibility of epochs behaving differently than Raw/Evoked for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review @drammock.
I understand the concern about code duplication. I initially tried modifying the shared _handle_tmin_tmax in mixin.py, but adding use_rounding=True there caused regressions in Raw tests (shifting data by one sample on Windows environments due to float precision). That's why I attempted the override in Epochs.
The core issue linked (#13634) is that epochs.crop(tmin=t) includes a sample that epochs.get_data(tmin=t) excludes. Since crop uses rounding internally, users expect get_data to match that behavior for consistency.
If modifying the global mixin.py is risky for Raw backward compatibility, and overriding in Epochs is discouraged, do you have a suggestion on how to reconcile get_data with crop for Epochs specifically? Maybe passing a round_tmin argument to get_data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, that was clear from the issue description.
I suspect that the problem is not limited to Epochs, but also affects Raw and Evoked (and TFR... anything that inherits the mixin). I don't have a suggestion off the top of my head; as I said before, this will need some discussion. Changing how
get_data()works (to accord withcrop()) --- or vice-versa --- has potentially wide-reaching consequences. I know it's a single sample, but as you've seen it's enough to break our tests, and it's also enough to change the results of user's existing analysis code, or even cause that code to crash if re-run. We don't take that lightly.