-
Notifications
You must be signed in to change notification settings - Fork 93
Refactor _handle_events_reading to allow extracting annotation information stand-alone #1389
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
Conversation
Hello! 👋 Thanks for opening your first pull request here! |
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.
Hi @matthiasdold to make this function public, it would need to get a more extensive docstr (numpydoc), and preferably also be used in a public example.
You may (or not) also need to add it here in some way: https://github.com/mne-tools/mne-bids/blob/main/mne_bids/__init__.py
There are also some test failures here that I haven't looked into yet.
Hi @sappelhoff, thanks for checking this out.
Nevermind the above, you comment explains everything actually. I just did not know how Sphinx works properly. It is working now, but coverage goes down at bit. Would you want me to implement a test for this explicitly? Also, I had to add the |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1389 +/- ##
==========================================
+ Coverage 97.48% 97.49% +0.01%
==========================================
Files 40 40
Lines 9023 9060 +37
==========================================
+ Hits 8796 8833 +37
Misses 227 227 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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, it would be great if we could cover any differences introduced via this PR.
So you ended up leaving the function private 🤔 I think that if you want to use this in another library, it may be worth making it public. For that you could take one example function in mne-bids that is public, and see where it has to be declared, and then do the same for your function.
Otherwise, you always take the risk that is inherent in using private functions of another software package: backward incompatible changes may come at any time and without notice 🤔
If you decide that you do NOT want to make the function public and that you DO want to take the risk of using a private function, then you would at least have to adjust your changelog entry, as we usually do not talk about changes to private functions so explicitly. You could write something a bit more generic, like "refactoring of events filtering", under code health or so.
WDYT @drammock @hoechenberger ?
680b8e1
to
2dd91cc
Compare
fdac9c1
to
8868355
Compare
I wasn't super familiar with the internals of what MNE-BIDS did in terms of reading
|
Operating on a (pandas) dataframe would also lead to a more readable code, IMHO, as we can use standard filtering instead of I didn't go the dataframe route as I wanted to be minimally invasive. Happy to provide a dataframe version as well. |
e94019c
to
4fdf132
Compare
Thanks for your view, Dan. I agree with your points 1, 3 and 4 -- and regarding point 2, I think returning a dict is the way to go. We do not have pandas as a required dependency of mne-bids, and I don't think the current "feature" is enough to warrant it. |
@matthiasdold I think you need double backquotes for code samples. This might be why your doc build fails |
eda7182
to
4e6b554
Compare
for more information, see https://pre-commit.ci
Thx for the suggestion @PierreGtch - unfortunately this seems not to be the issue. As for the :func: part, all other lines only had single backquotes, so I would not expect this to be a porblem there (the error message states that I am a bit clueless here... |
@matthiasdold your issue is not anymore with building the doc but before, when the ci is trying to pull the code |
yes, something is fishy with circleci. I just opened #1391 with tiny changes to see if I get a circleci issue there as well. If I don't, then maybe the failures ARE related to the PR here, but it looks almost like they aren't. |
the error looks totally related to me:
same error here:
|
add the new public function name to |
I was talking about this one: |
yet #1391 is unaffected, so it must be something about this PR. |
ok fine, the errors that circleci now provides all seem meaningful and related :-) no idea what I was after in #1389 (comment) @matthiasdold this should be possible for you to address. I am +1 for merging once everything is green. thanks a lot! |
mne_bids/read.py
Outdated
Notes | ||
----- | ||
The function handles the following cases: | ||
- If the `trial_type` column is available, it uses it for event descriptions. |
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.
add blank line before bullet list starts
here's the rendered docstring: see how the notes section bullet list isn't formatted right, and the formatting in the Returns section is inconsistent. |
Thanks a lot @drammock for the detailed explanation! I should get it sorted out now. My first time working with circleci (as you of course must have guessed), so I was not aware that I could look at the artifacts. Thanks for your patients @drammock and @sappelhoff 😅 |
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.
LGTM, thanks for the thorough test. Left a few nitpick comments that you can feel free to ignore or implement.
assert (ev_kwargs_filtered["onset"] == dext_f["onset"].astype(float).values).all() | ||
assert ( | ||
ev_kwargs_filtered["duration"] | ||
== dext_f["duration"].replace("n/a", "0.0").astype(float).values | ||
).all() | ||
assert (ev_kwargs_filtered["description"] == dext_f["trial_type"].values).all() | ||
assert ( | ||
ev_kwargs_filtered["duration"][0] == 0.0 | ||
) # now idx=0, as first row is filtered out |
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.
idem. Could also consider pd.testing.assert_frame_equal
but that would require converting the dict to dataframe first.
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.
As we are using a dict for the return type, I would just stick to comparing the iterables here. Implemented all other suggestions though.
for more information, see https://pre-commit.ci
Once mne-tools/mne-python#13213 is implemented in |
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 @matthiasdold!
🎉 Congrats on merging your first pull request! 🥳 Looking forward to seeing more from you in the future! 💪 |
a separate one, please! :) |
PR Description
Aim:
The
_handle_events_reading
in read.py reads onsets, duration and descriptions/event_ids from theevents.tsv
, then filters the columns for n\a values etc. and finally sets annotations to the raw object based on these filtered version of theevents.tsv
data.On default, this will encode information from three columns within the
events.tsv
.In order to extract additional information from BIDS dataset within MOABB it would be necessary to ensure that all annotations that end up in the raw and whatever is extracted from the
events.tsv
are aligned. To allow for this, it would be necessary to have any filtering that happens in L526-602 accessible standalone (without the need to provide araw
).Proposition:
Simply have the first part of the
_handle_events_reading
as its own function which returns the filtered version of the onset, description, duration and event_ids. Assuming that these columns would form a primary key within theevents.tsv
, we could always map additional meta info to the annotations in the raw unambiguously.Merge checklist
Maintainer, please confirm the following before merging.
If applicable: