{"action":"created","comment":{"url":"https://api.github.com/repos/numpy/numpy/pulls/comments/32852506","id":32852506,"diff_hunk":"@@ -423,6 +423,12 @@ def __new__(subtype, shape, dtype=None, buf=None, offset=0, strides=None,\n                                       strides=strides, order=order)\n         return self\n \n+    def __array_finalize__(self, obj):\n+        if type(obj) is not type(self):\n+            # invoke __setattr__, which for void dtypes will do\n+            # self.dtype = sb.dtype((record, self.dtype))\n+            self.dtype = self.dtype","path":"numpy/core/records.py","position":8,"original_position":8,"commit_id":"f8b5308163ca2c88d8912e597778786176e5e11e","original_commit_id":"f8b5308163ca2c88d8912e597778786176e5e11e","user":{"login":"mhvk","id":2789820,"avatar_url":"https://avatars.githubusercontent.com/u/2789820?v=3","gravatar_id":"","url":"https://api.github.com/users/mhvk","html_url":"https://github.com/mhvk","followers_url":"https://api.github.com/users/mhvk/followers","following_url":"https://api.github.com/users/mhvk/following{/other_user}","gists_url":"https://api.github.com/users/mhvk/gists{/gist_id}","starred_url":"https://api.github.com/users/mhvk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhvk/subscriptions","organizations_url":"https://api.github.com/users/mhvk/orgs","repos_url":"https://api.github.com/users/mhvk/repos","events_url":"https://api.github.com/users/mhvk/events{/privacy}","received_events_url":"https://api.github.com/users/mhvk/received_events","type":"User","site_admin":false},"body":"OK, if you need it to be set also for explicit construction then, yes, your case is the right one. Since this was not obvious to me, and therefore may not be obvious to a future person looking at the code, maybe write the comment as:\r\n```\r\n# Both when constructing a new instance (obj=None) and when viewing\r\n# from another class -- obj.view(type(self)) -- we invoke __setattr__,\r\n# which for void dtypes will do self.dtype = sb.dtype((record, self.dtype)).\r\n```","created_at":"2015-06-19T17:52:27Z","updated_at":"2015-06-19T17:52:27Z","html_url":"https://github.com/numpy/numpy/pull/5943#discussion_r32852506","pull_request_url":"https://api.github.com/repos/numpy/numpy/pulls/5943","_links":{"self":{"href":"https://api.github.com/repos/numpy/numpy/pulls/comments/32852506"},"html":{"href":"https://github.com/numpy/numpy/pull/5943#discussion_r32852506"},"pull_request":{"href":"https://api.github.com/repos/numpy/numpy/pulls/5943"}}},"pull_request":{"url":"https://api.github.com/repos/numpy/numpy/pulls/5943","id":37048339,"html_url":"https://github.com/numpy/numpy/pull/5943","diff_url":"https://github.com/numpy/numpy/pull/5943.diff","patch_url":"https://github.com/numpy/numpy/pull/5943.patch","issue_url":"https://api.github.com/repos/numpy/numpy/issues/5943","number":5943,"state":"open","locked":false,"title":"BUG: automatically convert recarray dtype to np.record","user":{"login":"ahaldane","id":9040124,"avatar_url":"https://avatars.githubusercontent.com/u/9040124?v=3","gravatar_id":"","url":"https://api.github.com/users/ahaldane","html_url":"https://github.com/ahaldane","followers_url":"https://api.github.com/users/ahaldane/followers","following_url":"https://api.github.com/users/ahaldane/following{/other_user}","gists_url":"https://api.github.com/users/ahaldane/gists{/gist_id}","starred_url":"https://api.github.com/users/ahaldane/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahaldane/subscriptions","organizations_url":"https://api.github.com/users/ahaldane/orgs","repos_url":"https://api.github.com/users/ahaldane/repos","events_url":"https://api.github.com/users/ahaldane/events{/privacy}","received_events_url":"https://api.github.com/users/ahaldane/received_events","type":"User","site_admin":false},"body":"As discussed in #3581, this PR automatically converts the dtype of `np.recarray`s to `np.record`. \r\n\r\nTo get unit tests to pass I also had to add a setattr to the `MaskedArray` class: MaskedArrays did not support assignment to dtype attribute, as demonstrated in the following examples:\r\n\r\n    >>> a = np.zeros(4, dtype='f4,i4')\r\n    >>> m = np.ma.array(a)\r\n    >>> m.dtype = np.dtype('f8')\r\n    >>> m   # Exception\r\n    >>> a.view(dtype='f8', type=np.ma.MaskedArray) #Exception\r\n\r\nMaskedArray.setattr now catches assignments to dtype and updates the mask accordingly.\r\n\r\n\r\nPossible issues with this PR, if anyone has any ideas: \r\n\r\n1) Viewing as `a.view(np.recarray)` now changes the dtype. It's not totally clear to me this won't break anything. (Example: It broke maskedarrays above, but due to a maskedaray bug).\r\n\r\n2) Another example of the last point: Views are not reversible.\r\n\r\n    >>> a = np.zeros(4, 'f4,i4')\r\n    >>> b = a.view(np.recarray).view(np.ndarray)\r\n    >>> b.dtype\r\n    dtype((numpy.record, [('f0', '<f4'), ('f1', '<i4')]))\r\n\r\n3) Note (not really a problem): Attempt to create record arrays of non-structured type does not set the dtype to `np.record` (since it is not possible to do so). This is not new to this PR.\r\n\r\n    >>> a = np.zeros(5, 'f8')\r\n    >>> np.rec.array(a)\r\n    array([ 0.,  0.,  0.,  0.], \r\n          dtype=float64).view(numpy.recarray)\r\n    \r\nBenefits:\r\n\r\n * Goal is to improve results in #3581\r\n\r\nI still need to finish writing unit tests","created_at":"2015-06-05T16:39:24Z","updated_at":"2015-06-19T17:52:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7b68e1edaa1f58a3a8802a1fac8a1fc6410aab21","assignee":null,"milestone":{"url":"https://api.github.com/repos/numpy/numpy/milestones/35","html_url":"https://github.com/numpy/numpy/milestones/1.10.0%20release","labels_url":"https://api.github.com/repos/numpy/numpy/milestones/35/labels","id":1055363,"number":35,"title":"1.10.0 release","description":"Marker for PRs that should go into Numpy 1.10.1.","creator":{"login":"charris","id":77272,"avatar_url":"https://avatars.githubusercontent.com/u/77272?v=3","gravatar_id":"","url":"https://api.github.com/users/charris","html_url":"https://github.com/charris","followers_url":"https://api.github.com/users/charris/followers","following_url":"https://api.github.com/users/charris/following{/other_user}","gists_url":"https://api.github.com/users/charris/gists{/gist_id}","starred_url":"https://api.github.com/users/charris/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/charris/subscriptions","organizations_url":"https://api.github.com/users/charris/orgs","repos_url":"https://api.github.com/users/charris/repos","events_url":"https://api.github.com/users/charris/events{/privacy}","received_events_url":"https://api.github.com/users/charris/received_events","type":"User","site_admin":false},"open_issues":6,"closed_issues":46,"state":"open","created_at":"2015-04-07T00:02:10Z","updated_at":"2015-06-19T07:54:11Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/numpy/numpy/pulls/5943/commits","review_comments_url":"https://api.github.com/repos/numpy/numpy/pulls/5943/comments","review_comment_url":"https://api.github.com/repos/numpy/numpy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/numpy/numpy/issues/5943/comments","statuses_url":"https://api.github.com/repos/numpy/numpy/statuses/f8b5308163ca2c88d8912e597778786176e5e11e","head":{"label":"ahaldane:record_finalize","ref":"record_finalize","sha":"f8b5308163ca2c88d8912e597778786176e5e11e","user":{"login":"ahaldane","id":9040124,"avatar_url":"https://avatars.githubusercontent.com/u/9040124?v=3","gravatar_id":"","url":"https://api.github.com/users/ahaldane","html_url":"https://github.com/ahaldane","followers_url":"https://api.github.com/users/ahaldane/followers","following_url":"https://api.github.com/users/ahaldane/following{/other_user}","gists_url":"https://api.github.com/users/ahaldane/gists{/gist_id}","starred_url":"https://api.github.com/users/ahaldane/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahaldane/subscriptions","organizations_url":"https://api.github.com/users/ahaldane/orgs","repos_url":"https://api.github.com/users/ahaldane/repos","events_url":"https://api.github.com/users/ahaldane/events{/privacy}","received_events_url":"https://api.github.com/users/ahaldane/received_events","type":"User","site_admin":false},"repo":{"id":29257804,"name":"numpy","full_name":"ahaldane/numpy","owner":{"login":"ahaldane","id":9040124,"avatar_url":"https://avatars.githubusercontent.com/u/9040124?v=3","gravatar_id":"","url":"https://api.github.com/users/ahaldane","html_url":"https://github.com/ahaldane","followers_url":"https://api.github.com/users/ahaldane/followers","following_url":"https://api.github.com/users/ahaldane/following{/other_user}","gists_url":"https://api.github.com/users/ahaldane/gists{/gist_id}","starred_url":"https://api.github.com/users/ahaldane/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahaldane/subscriptions","organizations_url":"https://api.github.com/users/ahaldane/orgs","repos_url":"https://api.github.com/users/ahaldane/repos","events_url":"https://api.github.com/users/ahaldane/events{/privacy}","received_events_url":"https://api.github.com/users/ahaldane/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ahaldane/numpy","description":"Numpy main repository","fork":true,"url":"https://api.github.com/repos/ahaldane/numpy","forks_url":"https://api.github.com/repos/ahaldane/numpy/forks","keys_url":"https://api.github.com/repos/ahaldane/numpy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ahaldane/numpy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ahaldane/numpy/teams","hooks_url":"https://api.github.com/repos/ahaldane/numpy/hooks","issue_events_url":"https://api.github.com/repos/ahaldane/numpy/issues/events{/number}","events_url":"https://api.github.com/repos/ahaldane/numpy/events","assignees_url":"https://api.github.com/repos/ahaldane/numpy/assignees{/user}","branches_url":"https://api.github.com/repos/ahaldane/numpy/branches{/branch}","tags_url":"https://api.github.com/repos/ahaldane/numpy/tags","blobs_url":"https://api.github.com/repos/ahaldane/numpy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ahaldane/numpy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ahaldane/numpy/git/refs{/sha}","trees_url":"https://api.github.com/repos/ahaldane/numpy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ahaldane/numpy/statuses/{sha}","languages_url":"https://api.github.com/repos/ahaldane/numpy/languages","stargazers_url":"https://api.github.com/repos/ahaldane/numpy/stargazers","contributors_url":"https://api.github.com/repos/ahaldane/numpy/contributors","subscribers_url":"https://api.github.com/repos/ahaldane/numpy/subscribers","subscription_url":"https://api.github.com/repos/ahaldane/numpy/subscription","commits_url":"https://api.github.com/repos/ahaldane/numpy/commits{/sha}","git_commits_url":"https://api.github.com/repos/ahaldane/numpy/git/commits{/sha}","comments_url":"https://api.github.com/repos/ahaldane/numpy/comments{/number}","issue_comment_url":"https://api.github.com/repos/ahaldane/numpy/issues/comments{/number}","contents_url":"https://api.github.com/repos/ahaldane/numpy/contents/{+path}","compare_url":"https://api.github.com/repos/ahaldane/numpy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ahaldane/numpy/merges","archive_url":"https://api.github.com/repos/ahaldane/numpy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ahaldane/numpy/downloads","issues_url":"https://api.github.com/repos/ahaldane/numpy/issues{/number}","pulls_url":"https://api.github.com/repos/ahaldane/numpy/pulls{/number}","milestones_url":"https://api.github.com/repos/ahaldane/numpy/milestones{/number}","notifications_url":"https://api.github.com/repos/ahaldane/numpy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ahaldane/numpy/labels{/name}","releases_url":"https://api.github.com/repos/ahaldane/numpy/releases{/id}","created_at":"2015-01-14T18:01:59Z","updated_at":"2015-01-25T23:16:50Z","pushed_at":"2015-06-19T15:00:46Z","git_url":"git://github.com/ahaldane/numpy.git","ssh_url":"git@github.com:ahaldane/numpy.git","clone_url":"https://github.com/ahaldane/numpy.git","svn_url":"https://github.com/ahaldane/numpy","homepage":"http://www.numpy.org/","size":40289,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"numpy:master","ref":"master","sha":"d033b6e19fc95a1f1fd6592de8318178368011b1","user":{"login":"numpy","id":288276,"avatar_url":"https://avatars.githubusercontent.com/u/288276?v=3","gravatar_id":"","url":"https://api.github.com/users/numpy","html_url":"https://github.com/numpy","followers_url":"https://api.github.com/users/numpy/followers","following_url":"https://api.github.com/users/numpy/following{/other_user}","gists_url":"https://api.github.com/users/numpy/gists{/gist_id}","starred_url":"https://api.github.com/users/numpy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/numpy/subscriptions","organizations_url":"https://api.github.com/users/numpy/orgs","repos_url":"https://api.github.com/users/numpy/repos","events_url":"https://api.github.com/users/numpy/events{/privacy}","received_events_url":"https://api.github.com/users/numpy/received_events","type":"Organization","site_admin":false},"repo":{"id":908607,"name":"numpy","full_name":"numpy/numpy","owner":{"login":"numpy","id":288276,"avatar_url":"https://avatars.githubusercontent.com/u/288276?v=3","gravatar_id":"","url":"https://api.github.com/users/numpy","html_url":"https://github.com/numpy","followers_url":"https://api.github.com/users/numpy/followers","following_url":"https://api.github.com/users/numpy/following{/other_user}","gists_url":"https://api.github.com/users/numpy/gists{/gist_id}","starred_url":"https://api.github.com/users/numpy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/numpy/subscriptions","organizations_url":"https://api.github.com/users/numpy/orgs","repos_url":"https://api.github.com/users/numpy/repos","events_url":"https://api.github.com/users/numpy/events{/privacy}","received_events_url":"https://api.github.com/users/numpy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/numpy/numpy","description":"Numpy main repository","fork":false,"url":"https://api.github.com/repos/numpy/numpy","forks_url":"https://api.github.com/repos/numpy/numpy/forks","keys_url":"https://api.github.com/repos/numpy/numpy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/numpy/numpy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/numpy/numpy/teams","hooks_url":"https://api.github.com/repos/numpy/numpy/hooks","issue_events_url":"https://api.github.com/repos/numpy/numpy/issues/events{/number}","events_url":"https://api.github.com/repos/numpy/numpy/events","assignees_url":"https://api.github.com/repos/numpy/numpy/assignees{/user}","branches_url":"https://api.github.com/repos/numpy/numpy/branches{/branch}","tags_url":"https://api.github.com/repos/numpy/numpy/tags","blobs_url":"https://api.github.com/repos/numpy/numpy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/numpy/numpy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/numpy/numpy/git/refs{/sha}","trees_url":"https://api.github.com/repos/numpy/numpy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/numpy/numpy/statuses/{sha}","languages_url":"https://api.github.com/repos/numpy/numpy/languages","stargazers_url":"https://api.github.com/repos/numpy/numpy/stargazers","contributors_url":"https://api.github.com/repos/numpy/numpy/contributors","subscribers_url":"https://api.github.com/repos/numpy/numpy/subscribers","subscription_url":"https://api.github.com/repos/numpy/numpy/subscription","commits_url":"https://api.github.com/repos/numpy/numpy/commits{/sha}","git_commits_url":"https://api.github.com/repos/numpy/numpy/git/commits{/sha}","comments_url":"https://api.github.com/repos/numpy/numpy/comments{/number}","issue_comment_url":"https://api.github.com/repos/numpy/numpy/issues/comments{/number}","contents_url":"https://api.github.com/repos/numpy/numpy/contents/{+path}","compare_url":"https://api.github.com/repos/numpy/numpy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/numpy/numpy/merges","archive_url":"https://api.github.com/repos/numpy/numpy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/numpy/numpy/downloads","issues_url":"https://api.github.com/repos/numpy/numpy/issues{/number}","pulls_url":"https://api.github.com/repos/numpy/numpy/pulls{/number}","milestones_url":"https://api.github.com/repos/numpy/numpy/milestones{/number}","notifications_url":"https://api.github.com/repos/numpy/numpy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/numpy/numpy/labels{/name}","releases_url":"https://api.github.com/repos/numpy/numpy/releases{/id}","created_at":"2010-09-13T23:02:39Z","updated_at":"2015-06-19T06:14:06Z","pushed_at":"2015-06-19T17:36:14Z","git_url":"git://github.com/numpy/numpy.git","ssh_url":"git@github.com:numpy/numpy.git","clone_url":"https://github.com/numpy/numpy.git","svn_url":"https://github.com/numpy/numpy","homepage":"http://www.numpy.org/","size":66636,"stargazers_count":1986,"watchers_count":1986,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1025,"mirror_url":null,"open_issues_count":878,"forks":1025,"open_issues":878,"watchers":1986,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/numpy/numpy/pulls/5943"},"html":{"href":"https://github.com/numpy/numpy/pull/5943"},"issue":{"href":"https://api.github.com/repos/numpy/numpy/issues/5943"},"comments":{"href":"https://api.github.com/repos/numpy/numpy/issues/5943/comments"},"review_comments":{"href":"https://api.github.com/repos/numpy/numpy/pulls/5943/comments"},"review_comment":{"href":"https://api.github.com/repos/numpy/numpy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/numpy/numpy/pulls/5943/commits"},"statuses":{"href":"https://api.github.com/repos/numpy/numpy/statuses/f8b5308163ca2c88d8912e597778786176e5e11e"}}}}