Skip to content

Use properties to set values in Info #7818

Closed

Description

@cbrnr

As I've mentioned in #7816 I think it would be more intuitive if users could just set values in the Info dict using simple assignments, e.g. info['meas_date'] = None, instead of setter methods (e.g. info.set_meas_date(None)). This is consistent with values that we currently allow to be set directly, e.g. info["bads"] = [].

This would also allow us to make read-only properties for fields which users should not set manually.

Activity

  1. agramfort commented on May 24, 2020

    @agramfort
    SponsorMember
  2. cbrnr commented on May 24, 2020

    @cbrnr
    ContributorAuthor

    I totally agree with you - that's why I'd use properties instead of setters.

  3. hoechenberger commented on May 25, 2020

    @hoechenberger
    Member

    I agree with @cbrnr: Using properties would allow us to ensure "correct" usage – without having to invent and apply arbitrary rules. I think it makes sense to have this for the info structure, as it's one of the bits that users actually are expected to touch and modify. It's an API clarification, if you will. I don't think anyone is wanting to expand this to other parts of MNE for now. :)

  4. cbrnr commented on May 25, 2020

    @cbrnr
    ContributorAuthor

    No, this is just about the Info object. Intended changed usage examples:

    >>> raw.info["bads"] = ["C3", "Cz", "C4"]
    >>> raw.info["annotations"] = mne.Annotations(mne.Annotations(5, 1, "test"))
    >>> raw.info["sfreq"] = 254
    AttributeError: sampling frequency cannot be changed (consider resampling the signal)
    >>> raw.info["ch_names"] = ["X", "Y"]
    ValueError: number of channel names (2 given) must match number of channels (32)
    >>> raw.info["nchan"] = 30
    AttributeError: number of channels cannot be set (consider using drop_channels)
  5. agramfort commented on May 25, 2020

    @agramfort
    SponsorMember
  6. cbrnr commented on May 25, 2020

    @cbrnr
    ContributorAuthor

    Hehe, in case you're hoping that I will forget: I won't 😄.

    But I won't insist, if you say we don't need it - fine with me. I'd be interested what others think - especially from a user's point of view. Any opinions?

  7. hoechenberger commented on May 26, 2020

    @hoechenberger
    Member

    I'd be interested what others think - especially from a user's point of view. Any opinions?

    I was going to tag some users here, but I suppose not all of them would even know what this "properties" thing is supposed to be and when and how it would affect their work. If you feel like it, could you maybe write a short example to showcase what it is you mean? Then we could get users' opinions :) (You already have sth in your initial comment here, but its phrasing is IMHO mainly targeted towards developers still!)

  8. cbrnr commented on May 26, 2020

    @cbrnr
    ContributorAuthor

    Actually I just realized that the only setter method for Info objects is set_montage. So maybe documenting which fields are user-writable is sufficient.

  9. agramfort commented on May 26, 2020

    @agramfort
    SponsorMember
  10. hoechenberger commented on May 26, 2020

    @hoechenberger
    Member

    So maybe documenting which fields are user-writable is sufficient.

    And still using properties to avoid touching items you're not supposed to touch? Or what do you mean? :)

  11. cbrnr commented on May 26, 2020

    @cbrnr
    ContributorAuthor

    And still using properties to avoid touching items you're not supposed to touch? Or what do you mean? :)

    Nope, just document which fields are supposed to be touched and that's it.

  12. hoechenberger commented on May 26, 2020

    @hoechenberger
    Member

    Ok, sounds good! Just try to make sure it's, like… really, really in-your-face 😁

  13. cbrnr commented on May 26, 2020

    @cbrnr
    ContributorAuthor

    Yes, the note should be promoted to a warning or something.

  14. added this to the 0.21 milestone on May 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions