You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
info['meas_date'] changes during I/O roundtrip #7816
Reading some test data, setting its meas_date to None via raw.set_meas_date(), writing the altered file to disk, and reading it back produced an unexpected result: meas_date is notNone after reading, although it certainly was before writing.
meas_date is not one of the info entries that should be manually changed. You need to use the anonymize functions. meas_date is inferred from elsewhere when the file is not fully anonymized.
Wow, but, but, but… Why do we have a public set_meas_date() method then??
And, I always thought manually changing stuff in info was totally fine… After all, that is also how I change bads, subject info etc… If I'm only supposed to ever touch a subset of the info values, we should probably rethink access to this data structure.
Oh noes. I would like to discuss whether and how we could make info read-only and only allow alterations via dedicated setter functions (while keeping the ability to change the values of a few"safe" keys directly, for backward-compat). Anyone willing to chime in? ;)
Because it is really inconsistent and error-provoking. I'm being taught in the tutorials to manually fiddle with info['bads'], and now suddenly I'm being told that I actually shouldn't be touching most of the items in the info dict. – This is just in addition to having a set_meas_date function already, that will apparently not always really do what its name suggests, and leads to a situation where I write data to disk but reading it back doesn't produce the same stuff I had before writing. How is an ordinary user ever going to figure this out?
Oh noes. I would like to discuss whether and how we could make info read-only and only allow alterations via dedicated setter functions (while keeping the ability to change the values of a few"safe" keys directly, for backward-compat). Anyone willing to chime in? ;)
I'd be up for reconsidering adding it. I think now that we require an actual Info everywhere, it should be possible to at least warn people when they change an entry that they shouldn't, and maybe provide some expert or internal interface to allow it. I imagine we could do it with maybe a dozen lines in the Info class itself.
But even this wouldn't be the end of the problem. The entries in info itself are mutable (dict, list, ndarray). A separable step would be changing as many mutable entries of Info (e.g., list) to immutable ones (tuple), maybe also using some immutable dict where possible (e.g., info['chs'][ii]). FWIW this is also an issue when deep-copying info that we currently use some specialized code to deal with, so in the long run this step at least might make some things simpler.
Because it is really inconsistent and error-provoking. I'm being taught in the tutorials to manually fiddle with info['bads'], and now suddenly I'm being told that I actually shouldn't be touching most of the items in the info dict.
To start, we should update the early tutorial docs (if we haven't already) to make it clearer. Or make it clearer (with a .. warning:: perhaps?) in the Infodocstring that it says:
The only entries that should be manually changed by the user are info['bads']
and info['description']. All other entries should be considered read-only,
though they can be modified by various MNE-Python functions or methods
(which have safeguards to ensure all fields remain in sync).
– This is just in addition to having a set_meas_date function already, that will apparently not always really do what its name suggests, and leads to a situation where I write data to disk but reading it back doesn't produce the same stuff I had before writing.
This is a bug with set_meas_date. I thought you were doing info['meas_date'] = None manually, which is a no-no -- set_meas_date should indeed be used.
I agree that the info dict is not entirely ideal. I think this is due to two reasons: (1) it has grown historically/organically, and (2) it is reflecting the internal FIF data structure. Therefore, it's not easy to change this structure, but at least such things should be clearly documented.
"The only entries that should be manually changed by the user are info['bads'] and info['description']. All other entries should be considered read-only, though they can be modified by various MNE-Python functions or methods (which have safeguards to ensure all fields remain in sync).
The mne.Info tutorial doesn't really discuss how to write the various fields, so maybe we should add a dedicated section about this topic.
Regarding setters, I'm not a huge fan. The more Pythonic way is to use properties, which is really something I'd like to see more. I know the argument setters vs. properties (properties shouldn't be long-running functions), but most setters here are more or less simple assignments with some sanity checks, so most of the setters could actually be implemented as properties. For users, this makes everything much easier to figure out, because everything is changed directly via assignment (and only internally properties do the work under the hood).
I'd be up for reconsidering adding it. I think now that we require an actual Info everywhere, it should be possible to at least warn people when they change an entry that they shouldn't, and maybe provide some expert or internal interface to allow it. I imagine we could do it with maybe a dozen lines in the Info class itself.
But even this wouldn't be the end of the problem. The entries in info itself are mutable (dict, list, ndarray). A separable step would be changing as many mutable entries of Info (e.g., list) to immutable ones (tuple), maybe also using some immutable dict where possible (e.g., info['chs'][ii]). FWIW this is also an issue when deep-copying info that we currently use some specialized code to deal with, so in the long run this step at least might make some things simpler.
This is over-engineering IMO. Properties would make things much easier for users.
This is a bug with set_meas_date. I thought you were doing info['meas_date'] = None manually, which is a no-no -- set_meas_date should indeed be used.
Again, info['meas_date'] = None is much more intuitive and Pythonic. Let's implement properties.
Regarding setters, I'm not a huge fan. The more Pythonic way is to use properties, which is really something I'd like to see more. I know the argument setters vs. properties (properties shouldn't be long-running functions), but most setters here are more or less simple assignments with some sanity checks, so most of the setters could actually be implemented as properties.
This to me seems like a mostly orthogonal discussion -- here we are mostly talking about which properties should be settable at all and how to prevent errors. You are talking about how they should be set (and requiring deprecations of existing functions, etc.). Feel free to open a separate issue for this but I'd rather keep the discussion here focused on the read-only-ness / documentation of Info.
This to me seems like a mostly orthogonal discussion -- here we are mostly talking about which properties should be settable at all and how to prevent errors. You are talking about how they should be set (and requiring deprecations of existing functions, etc.). Feel free to open a separate issue for this but I'd rather keep the discussion here focused on the read-only-ness / documentation of Info.
True, but properties provide a Pythonic way to implement read-only fields - I'll open a separate issue to discuss.
I agree that here the best solution is to improve the docs (e.g. make the existing note more obvious as you suggested).
– This is just in addition to having a set_meas_date function already, that will apparently not always really do what its name suggests, and leads to a situation where I write data to disk but reading it back doesn't produce the same stuff I had before writing.
This is a bug with set_meas_date. I thought you were doing info['meas_date'] = None manually
… it's this one, in case anyone was wondering after our digression here. 😅
yes please focus what is the matter here. @hoechenberg uses a public method
set_meas_date
passes None, gets no warning as everything seems fine and then he hits
a legitimate surprise on read. So either we add a warning that says that
None
should not be passed or we consider this a bug and we fix it. I was
surprised
myself by the failure of the IO round trip and I suggested to open the
issue.
Adding code with eg properties is add a lot of complexity for an issue that
is for me orthogonal and info['meas_date'] = None was not done
Activity
larsoner commentedon May 23, 2020
meas_date is not one of the info entries that should be manually changed. You need to use the anonymize functions. meas_date is inferred from elsewhere when the file is not fully anonymized.
hoechenberger commentedon May 24, 2020
Wow, but, but, but… Why do we have a public
set_meas_date()method then??hoechenberger commentedon May 24, 2020
And, I always thought manually changing stuff in
infowas totally fine… After all, that is also how I changebads, subject info etc… If I'm only supposed to ever touch a subset of theinfovalues, we should probably rethink access to this data structure.hoechenberger commentedon May 24, 2020
Is this always the case, or does it only apply when
meas_dateisNone?hoechenberger commentedon May 24, 2020
Related:
#7772
#7774
bloyl commentedon May 24, 2020
For fun weekend reading here is the last time this was discussed:
#7067
#7071
hoechenberger commentedon May 24, 2020
Oh noes. I would like to discuss whether and how we could make
inforead-only and only allow alterations via dedicated setter functions (while keeping the ability to change the values of a few"safe" keys directly, for backward-compat). Anyone willing to chime in? ;)Because it is really inconsistent and error-provoking. I'm being taught in the tutorials to manually fiddle with
info['bads'], and now suddenly I'm being told that I actually shouldn't be touching most of the items in theinfodict. – This is just in addition to having aset_meas_datefunction already, that will apparently not always really do what its name suggests, and leads to a situation where I write data to disk but reading it back doesn't produce the same stuff I had before writing. How is an ordinary user ever going to figure this out?cc @cbrnr @drammock
larsoner commentedon May 24, 2020
Read this first:
#2300
#2765
#2860
#3147
I'd be up for reconsidering adding it. I think now that we require an actual
Infoeverywhere, it should be possible to at leastwarnpeople when they change an entry that they shouldn't, and maybe provide some expert or internal interface to allow it. I imagine we could do it with maybe a dozen lines in theInfoclass itself.But even this wouldn't be the end of the problem. The entries in
infoitself are mutable (dict, list, ndarray). A separable step would be changing as many mutable entries ofInfo(e.g., list) to immutable ones (tuple), maybe also using some immutable dict where possible (e.g.,info['chs'][ii]). FWIW this is also an issue when deep-copying info that we currently use some specialized code to deal with, so in the long run this step at least might make some things simpler.To start, we should update the early tutorial docs (if we haven't already) to make it clearer. Or make it clearer (with a
.. warning::perhaps?) in theInfodocstring that it says:This is a bug with
set_meas_date. I thought you were doinginfo['meas_date'] = Nonemanually, which is a no-no --set_meas_dateshould indeed be used.cbrnr commentedon May 24, 2020
I agree that the
infodict is not entirely ideal. I think this is due to two reasons: (1) it has grown historically/organically, and (2) it is reflecting the internal FIF data structure. Therefore, it's not easy to change this structure, but at least such things should be clearly documented.In fact, the documentation of
mne.Infosays:The
mne.Infotutorial doesn't really discuss how to write the various fields, so maybe we should add a dedicated section about this topic.Regarding setters, I'm not a huge fan. The more Pythonic way is to use properties, which is really something I'd like to see more. I know the argument setters vs. properties (properties shouldn't be long-running functions), but most setters here are more or less simple assignments with some sanity checks, so most of the setters could actually be implemented as properties. For users, this makes everything much easier to figure out, because everything is changed directly via assignment (and only internally properties do the work under the hood).
cbrnr commentedon May 24, 2020
This is over-engineering IMO. Properties would make things much easier for users.
Again,
info['meas_date'] = Noneis much more intuitive and Pythonic. Let's implement properties.larsoner commentedon May 24, 2020
This to me seems like a mostly orthogonal discussion -- here we are mostly talking about which properties should be settable at all and how to prevent errors. You are talking about how they should be set (and requiring deprecations of existing functions, etc.). Feel free to open a separate issue for this but I'd rather keep the discussion here focused on the read-only-ness / documentation of
Info.hoechenberger commentedon May 24, 2020
@cbrnr
Yes I agree that properties are the more Pythonic approach and should be preferred.
cbrnr commentedon May 24, 2020
True, but properties provide a Pythonic way to implement read-only fields - I'll open a separate issue to discuss.
I agree that here the best solution is to improve the docs (e.g. make the existing note more obvious as you suggested).
hoechenberger commentedon May 24, 2020
Just to get back to the original issue:
… it's this one, in case anyone was wondering after our digression here. 😅
agramfort commentedon May 24, 2020
cbrnr commentedon May 24, 2020
@agramfort sorry about the digression, all discussion on properties are now in #7818.