Repository navigation
Handle None-type for 'sex' in raw subject info before writing EDF - #11375
Conversation
|
Hello! 👋 Thanks for opening your first pull request here! ❤️ We will try to get back to you soon. 🚴🏽♂️ |
|
@sappelhoff can you have a look? thx |
| if sex is None: | ||
| warning_message = "'sex' not specified in " + \ | ||
| "raw.info.subject_info. Encoding as n/a: 2 " + \ | ||
| "for EDFwriter." | ||
| warn(message=warning_message) | ||
| sex = 0 | ||
|
|
There was a problem hiding this comment.
Rather than this it would probably be better to do below some if val is not None. I think this could live in _try_to_set_value.
This assumes EDF allows you to write a subset of the patient info...
There was a problem hiding this comment.
EDFwriter defines a standard self.__plus_gender = 2 at instantiation, so they actually handle subsets just fine. A if val is not None guard clause should result in the same as my implementation.
I actually avoided implementing it in _try_to_set_value because I thought it was not a general case, but looking through the functions in EDFwriter I see several numeric comparisons, so the issue could arise with other parts of the info.
Let me know what you think, and i'll push a change.
There was a problem hiding this comment.
I can live with either solution. If we go with this one, though, we shouldn't warn -- if the field is missing from the Raw instance then I think it's okay to just have it be n/a when written
There was a problem hiding this comment.
You can have a look at the change. I have generalized it to the cases of name, sex, and handedness for now. If a similar issue arises in the future for other fields, we could generalize it to more/all fields in the EDF header and move to _try_to_set_value.
|
Works for me! Just two remaining quick things I think:
FYI we plan to release tomorrow so if there's any way you can get these in today then they'll make it into 1.3, otherwise your PR will probably go into 1.4 and be backported |
|
... actually let me know in the next few hours if you can do this. If not, then I can push a quick commit to get it in. It would be good to get it into this release! |
|
I'm working on it now. I'll give you an update in a bit. |
Co-authored-by: Eric Larson <[email protected]>
|
@larsoner I added a test. It passes for this PR but not for I don't know if you have preferences for the placement of it. |
|
You're welcome! I'm looking forward to contributing more in the future! |
|
Am I supposed to do anything else? I can see it's scheduled for review, but will the merge complete automatically? |
|
I'm going to iterate in #11377 until it merges, then push a commit here that should get CIs green, at which point it should auto-merge. So you shouldn't need to do anything! |
|
🎉 Congrats on merging your first pull request! 🥳 Looking forward to seeing more from you in the future! 💪 |
No reference issue.
This changes fixes an issue where, when
'sex'is not specified in theraw.info["subject_info"], the export to .edf-raises aRunTimeError.The error occurs in
mne.export._edf._try_to_set_value(https://github.com/mne-tools/mne-python/blob/main/mne/export/_edf.py#L14) because a None is return atsex = subj_info.get('sex')inmne.export._edf._export_raw(https://github.com/mne-tools/mne-python/blob/main/mne/export/_edf.py#L193) if thesexkey does not exist.The solution checks if
sexis None, and, if so, changes it to0.