{"action":"created","issue":{"url":"https://api.github.com/repos/mne-tools/mne-python/issues/2765","repository_url":"https://api.github.com/repos/mne-tools/mne-python","labels_url":"https://api.github.com/repos/mne-tools/mne-python/issues/2765/labels{/name}","comments_url":"https://api.github.com/repos/mne-tools/mne-python/issues/2765/comments","events_url":"https://api.github.com/repos/mne-tools/mne-python/issues/2765/events","html_url":"https://github.com/mne-tools/mne-python/pull/2765","id":124775610,"number":2765,"title":"[MRG] Automatic info['nchan'] and info['ch_names']","user":{"login":"wmvanvliet","id":428273,"avatar_url":"https://avatars.githubusercontent.com/u/428273?v=3","gravatar_id":"","url":"https://api.github.com/users/wmvanvliet","html_url":"https://github.com/wmvanvliet","followers_url":"https://api.github.com/users/wmvanvliet/followers","following_url":"https://api.github.com/users/wmvanvliet/following{/other_user}","gists_url":"https://api.github.com/users/wmvanvliet/gists{/gist_id}","starred_url":"https://api.github.com/users/wmvanvliet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wmvanvliet/subscriptions","organizations_url":"https://api.github.com/users/wmvanvliet/orgs","repos_url":"https://api.github.com/users/wmvanvliet/repos","events_url":"https://api.github.com/users/wmvanvliet/events{/privacy}","received_events_url":"https://api.github.com/users/wmvanvliet/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/mne-tools/mne-python/milestones/8","html_url":"https://github.com/mne-tools/mne-python/milestones/0.12","labels_url":"https://api.github.com/repos/mne-tools/mne-python/milestones/8/labels","id":1429321,"number":8,"title":"0.12","description":"","creator":{"login":"Eric89GXL","id":2365790,"avatar_url":"https://avatars.githubusercontent.com/u/2365790?v=3","gravatar_id":"","url":"https://api.github.com/users/Eric89GXL","html_url":"https://github.com/Eric89GXL","followers_url":"https://api.github.com/users/Eric89GXL/followers","following_url":"https://api.github.com/users/Eric89GXL/following{/other_user}","gists_url":"https://api.github.com/users/Eric89GXL/gists{/gist_id}","starred_url":"https://api.github.com/users/Eric89GXL/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Eric89GXL/subscriptions","organizations_url":"https://api.github.com/users/Eric89GXL/orgs","repos_url":"https://api.github.com/users/Eric89GXL/repos","events_url":"https://api.github.com/users/Eric89GXL/events{/privacy}","received_events_url":"https://api.github.com/users/Eric89GXL/received_events","type":"User","site_admin":false},"open_issues":32,"closed_issues":35,"state":"open","created_at":"2015-11-25T13:36:18Z","updated_at":"2016-02-05T17:05:07Z","due_on":"2016-04-29T04:00:00Z","closed_at":null},"comments":69,"created_at":"2016-01-04T15:10:00Z","updated_at":"2016-02-08T12:25:22Z","closed_at":"2016-02-03T14:02:07Z","pull_request":{"url":"https://api.github.com/repos/mne-tools/mne-python/pulls/2765","html_url":"https://github.com/mne-tools/mne-python/pull/2765","diff_url":"https://github.com/mne-tools/mne-python/pull/2765.diff","patch_url":"https://github.com/mne-tools/mne-python/pull/2765.patch"},"body":"The info object has two redundant fields: `nchan` and `ch_names`. They are there as convenience fields. However, whenever the `chs` list is updated, these fields need to be manually updated as well.\r\n\r\nThis PR makes these fields behave more like properties.\r\n\r\nIt does so by making `Info` a subclass of `collections.MutableMapping`, which allows it to redefine `__setitem__` and `__getitem__` while retaining full compatibility with the default Python dict.\r\n\r\nThe `nchan` field just maps to `len(info['chs'])`.\r\n\r\nThe `ch_names` field is a bit more tricky. From the outside, it behaves as a mapping to `[ch['ch_name'] for ch in info['chs']]`. However, in order not to generate a new list every time the field is accessed, the field is an instance of `_ChannelNameList`.\r\n\r\nThe `_ChannelNameList` class is a subclass of `collections.Sequence`, thus implementing a list that is read-only, but otherwise fully compatible with a normal Python list. It overwrites the `__getitem(self, index)__` method to map to `info['chs'][index]['ch_name']` on the fly. It also defines a neat `make_index_map()` function that generates a dictionary that maps channel names to integer indices, which can be used to speed things up when many lookups are needed.\r\n\r\nThe rest of the code is updated to no longer set the `nchan` and `ch_names` fields of Info objects.\r\n\r\nCloses #2300 "},"comment":{"url":"https://api.github.com/repos/mne-tools/mne-python/issues/comments/181344883","html_url":"https://github.com/mne-tools/mne-python/pull/2765#issuecomment-181344883","issue_url":"https://api.github.com/repos/mne-tools/mne-python/issues/2765","id":181344883,"user":{"login":"jasmainak","id":15852194,"avatar_url":"https://avatars.githubusercontent.com/u/15852194?v=3","gravatar_id":"","url":"https://api.github.com/users/jasmainak","html_url":"https://github.com/jasmainak","followers_url":"https://api.github.com/users/jasmainak/followers","following_url":"https://api.github.com/users/jasmainak/following{/other_user}","gists_url":"https://api.github.com/users/jasmainak/gists{/gist_id}","starred_url":"https://api.github.com/users/jasmainak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jasmainak/subscriptions","organizations_url":"https://api.github.com/users/jasmainak/orgs","repos_url":"https://api.github.com/users/jasmainak/repos","events_url":"https://api.github.com/users/jasmainak/events{/privacy}","received_events_url":"https://api.github.com/users/jasmainak/received_events","type":"User","site_admin":false},"created_at":"2016-02-08T12:25:22Z","updated_at":"2016-02-08T12:25:22Z","body":"> Protecting single keys still seems really weird to me, I cannot get used to this idea.\r\n\r\nThis is something I agree with. It's not documented and people with stumble on it because they think that the `Info` is a simple dict."}}