{"action":"opened","number":7652,"pull_request":{"url":"https://api.github.com/repos/astropy/astropy/pulls/7652","id":201394057,"node_id":"MDExOlB1bGxSZXF1ZXN0MjAxMzk0MDU3","html_url":"https://github.com/astropy/astropy/pull/7652","diff_url":"https://github.com/astropy/astropy/pull/7652.diff","patch_url":"https://github.com/astropy/astropy/pull/7652.patch","issue_url":"https://api.github.com/repos/astropy/astropy/issues/7652","number":7652,"state":"open","locked":false,"title":"Introduce | as the operator to get Quantity views of arrays.","user":{"login":"mhvk","id":2789820,"node_id":"MDQ6VXNlcjI3ODk4MjA=","avatar_url":"https://avatars0.githubusercontent.com/u/2789820?v=4","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":"As well as possibly in-place unit conversion of Quantities. Following https://github.com/astropy/astropy/issues/3174#issuecomment-404802610 and https://github.com/astropy/astropy/issues/3174#issuecomment-404875614.\r\n\r\nTimings:\r\n```\r\na = np.arange(100000.)\r\n%timeit a * u.m\r\n# 10000 loops, best of 5: 36.8 µs per loop\r\n%timeit a | u.m\r\n# 100000 loops, best of 5: 4.73 µs per loop\r\n```\r\nTo get a sense of how it should behave otherwise, here are the relevant tests.\r\n```\r\n    def test_creation_via_view(self):\r\n        # This works but is no better than 1. * u.m\r\n        q1 = 1. | u.m\r\n        assert isinstance(q1, u.Quantity)\r\n        assert q1.unit == u.m\r\n        assert q1.value == 1.\r\n        # With an array, we get an acual view.\r\n        a2 = np.arange(10.)\r\n        q2 = a2 | u.m / u.s\r\n        assert isinstance(q2, u.Quantity)\r\n        assert q2.unit == u.m / u.s\r\n        assert np.all(q2.value == a2)\r\n        a2[9] = 0.\r\n        assert np.all(q2.value == a2)\r\n        # But with a unit change we get a copy.\r\n        q3 = q2 | u.mm / u.s\r\n        assert isinstance(q3, u.Quantity)\r\n        assert q3.unit == u.mm / u.s\r\n        assert np.all(q3.value == a2 * 1000.)\r\n        a2[8] = 0.\r\n        assert q3[8].value == 8000.\r\n        # Without a unit change, we do get a view.\r\n        q4 = q2 | q2.unit\r\n        a2[7] = 0.\r\n        assert np.all(q4.value == a2)\r\n        with pytest.raises(u.UnitsError):\r\n            q2 | u.s\r\n        # But one can do an in-place unit change.\r\n        a2_copy = a2.copy()\r\n        q2 |= u.mm / u.s\r\n        # Of course, this change a2 as well.\r\n        assert np.all(q2.value == a2)\r\n        # Sanity check on the values.\r\n        assert np.all(q2.value == a2_copy * 1000.)\r\n        a2[8] = -1.\r\n        # Using quantities, one can also work with strings.\r\n        q5 = q2 | 'km/hr'\r\n        assert q5.unit == u.km / u.hr\r\n        assert np.all(q5 == q2)\r\n        # Finally, we can use scalar quantities as units.\r\n        not_quite_a_foot = 30. * u.cm\r\n        a6 = np.arange(5.)\r\n        q6 = a6 | not_quite_a_foot\r\n        assert q6.unit == u.Unit(not_quite_a_foot)\r\n        assert np.all(q6.to_value(u.cm) == 30. * a6)\r\n```","created_at":"2018-07-13T20:34:23Z","updated_at":"2018-07-13T20:34:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":145666575,"node_id":"MDU6TGFiZWwxNDU2NjY1NzU=","url":"https://api.github.com/repos/astropy/astropy/labels/Enhancement","name":"Enhancement","color":"fad8c7","default":false},{"id":12456977,"node_id":"MDU6TGFiZWwxMjQ1Njk3Nw==","url":"https://api.github.com/repos/astropy/astropy/labels/units","name":"units","color":"c7def8","default":false}],"milestone":{"url":"https://api.github.com/repos/astropy/astropy/milestones/52","html_url":"https://github.com/astropy/astropy/milestone/52","labels_url":"https://api.github.com/repos/astropy/astropy/milestones/52/labels","id":2929745,"node_id":"MDk6TWlsZXN0b25lMjkyOTc0NQ==","number":52,"title":"v3.1","description":"","creator":{"login":"eteq","id":346587,"node_id":"MDQ6VXNlcjM0NjU4Nw==","avatar_url":"https://avatars1.githubusercontent.com/u/346587?v=4","gravatar_id":"","url":"https://api.github.com/users/eteq","html_url":"https://github.com/eteq","followers_url":"https://api.github.com/users/eteq/followers","following_url":"https://api.github.com/users/eteq/following{/other_user}","gists_url":"https://api.github.com/users/eteq/gists{/gist_id}","starred_url":"https://api.github.com/users/eteq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eteq/subscriptions","organizations_url":"https://api.github.com/users/eteq/orgs","repos_url":"https://api.github.com/users/eteq/repos","events_url":"https://api.github.com/users/eteq/events{/privacy}","received_events_url":"https://api.github.com/users/eteq/received_events","type":"User","site_admin":false},"open_issues":82,"closed_issues":81,"state":"open","created_at":"2017-11-21T23:24:18Z","updated_at":"2018-07-13T20:34:23Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/astropy/astropy/pulls/7652/commits","review_comments_url":"https://api.github.com/repos/astropy/astropy/pulls/7652/comments","review_comment_url":"https://api.github.com/repos/astropy/astropy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/astropy/astropy/issues/7652/comments","statuses_url":"https://api.github.com/repos/astropy/astropy/statuses/7df7479e220916dec7a701c5c6ef7e85c4a1bbe7","head":{"label":"mhvk:unit-array-to-quantity","ref":"unit-array-to-quantity","sha":"7df7479e220916dec7a701c5c6ef7e85c4a1bbe7","user":{"login":"mhvk","id":2789820,"node_id":"MDQ6VXNlcjI3ODk4MjA=","avatar_url":"https://avatars0.githubusercontent.com/u/2789820?v=4","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},"repo":{"id":9993739,"node_id":"MDEwOlJlcG9zaXRvcnk5OTkzNzM5","name":"astropy","full_name":"mhvk/astropy","owner":{"login":"mhvk","id":2789820,"node_id":"MDQ6VXNlcjI3ODk4MjA=","avatar_url":"https://avatars0.githubusercontent.com/u/2789820?v=4","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},"private":false,"html_url":"https://github.com/mhvk/astropy","description":"Main AstroPy repository","fork":true,"url":"https://api.github.com/repos/mhvk/astropy","forks_url":"https://api.github.com/repos/mhvk/astropy/forks","keys_url":"https://api.github.com/repos/mhvk/astropy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mhvk/astropy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mhvk/astropy/teams","hooks_url":"https://api.github.com/repos/mhvk/astropy/hooks","issue_events_url":"https://api.github.com/repos/mhvk/astropy/issues/events{/number}","events_url":"https://api.github.com/repos/mhvk/astropy/events","assignees_url":"https://api.github.com/repos/mhvk/astropy/assignees{/user}","branches_url":"https://api.github.com/repos/mhvk/astropy/branches{/branch}","tags_url":"https://api.github.com/repos/mhvk/astropy/tags","blobs_url":"https://api.github.com/repos/mhvk/astropy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mhvk/astropy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mhvk/astropy/git/refs{/sha}","trees_url":"https://api.github.com/repos/mhvk/astropy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mhvk/astropy/statuses/{sha}","languages_url":"https://api.github.com/repos/mhvk/astropy/languages","stargazers_url":"https://api.github.com/repos/mhvk/astropy/stargazers","contributors_url":"https://api.github.com/repos/mhvk/astropy/contributors","subscribers_url":"https://api.github.com/repos/mhvk/astropy/subscribers","subscription_url":"https://api.github.com/repos/mhvk/astropy/subscription","commits_url":"https://api.github.com/repos/mhvk/astropy/commits{/sha}","git_commits_url":"https://api.github.com/repos/mhvk/astropy/git/commits{/sha}","comments_url":"https://api.github.com/repos/mhvk/astropy/comments{/number}","issue_comment_url":"https://api.github.com/repos/mhvk/astropy/issues/comments{/number}","contents_url":"https://api.github.com/repos/mhvk/astropy/contents/{+path}","compare_url":"https://api.github.com/repos/mhvk/astropy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mhvk/astropy/merges","archive_url":"https://api.github.com/repos/mhvk/astropy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mhvk/astropy/downloads","issues_url":"https://api.github.com/repos/mhvk/astropy/issues{/number}","pulls_url":"https://api.github.com/repos/mhvk/astropy/pulls{/number}","milestones_url":"https://api.github.com/repos/mhvk/astropy/milestones{/number}","notifications_url":"https://api.github.com/repos/mhvk/astropy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mhvk/astropy/labels{/name}","releases_url":"https://api.github.com/repos/mhvk/astropy/releases{/id}","deployments_url":"https://api.github.com/repos/mhvk/astropy/deployments","created_at":"2013-05-11T02:02:37Z","updated_at":"2018-07-12T21:32:08Z","pushed_at":"2018-07-13T20:33:39Z","git_url":"git://github.com/mhvk/astropy.git","ssh_url":"git@github.com:mhvk/astropy.git","clone_url":"https://github.com/mhvk/astropy.git","svn_url":"https://github.com/mhvk/astropy","homepage":"astropy.org","size":65298,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"placeholder"}},"base":{"label":"astropy:master","ref":"master","sha":"6417f7936de752a44cda010cc26ca79b0208b1b6","user":{"login":"astropy","id":847984,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg0Nzk4NA==","avatar_url":"https://avatars0.githubusercontent.com/u/847984?v=4","gravatar_id":"","url":"https://api.github.com/users/astropy","html_url":"https://github.com/astropy","followers_url":"https://api.github.com/users/astropy/followers","following_url":"https://api.github.com/users/astropy/following{/other_user}","gists_url":"https://api.github.com/users/astropy/gists{/gist_id}","starred_url":"https://api.github.com/users/astropy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/astropy/subscriptions","organizations_url":"https://api.github.com/users/astropy/orgs","repos_url":"https://api.github.com/users/astropy/repos","events_url":"https://api.github.com/users/astropy/events{/privacy}","received_events_url":"https://api.github.com/users/astropy/received_events","type":"Organization","site_admin":false},"repo":{"id":2081289,"node_id":"MDEwOlJlcG9zaXRvcnkyMDgxMjg5","name":"astropy","full_name":"astropy/astropy","owner":{"login":"astropy","id":847984,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg0Nzk4NA==","avatar_url":"https://avatars0.githubusercontent.com/u/847984?v=4","gravatar_id":"","url":"https://api.github.com/users/astropy","html_url":"https://github.com/astropy","followers_url":"https://api.github.com/users/astropy/followers","following_url":"https://api.github.com/users/astropy/following{/other_user}","gists_url":"https://api.github.com/users/astropy/gists{/gist_id}","starred_url":"https://api.github.com/users/astropy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/astropy/subscriptions","organizations_url":"https://api.github.com/users/astropy/orgs","repos_url":"https://api.github.com/users/astropy/repos","events_url":"https://api.github.com/users/astropy/events{/privacy}","received_events_url":"https://api.github.com/users/astropy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/astropy/astropy","description":"Repository for the Astropy core package","fork":false,"url":"https://api.github.com/repos/astropy/astropy","forks_url":"https://api.github.com/repos/astropy/astropy/forks","keys_url":"https://api.github.com/repos/astropy/astropy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/astropy/astropy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/astropy/astropy/teams","hooks_url":"https://api.github.com/repos/astropy/astropy/hooks","issue_events_url":"https://api.github.com/repos/astropy/astropy/issues/events{/number}","events_url":"https://api.github.com/repos/astropy/astropy/events","assignees_url":"https://api.github.com/repos/astropy/astropy/assignees{/user}","branches_url":"https://api.github.com/repos/astropy/astropy/branches{/branch}","tags_url":"https://api.github.com/repos/astropy/astropy/tags","blobs_url":"https://api.github.com/repos/astropy/astropy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/astropy/astropy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/astropy/astropy/git/refs{/sha}","trees_url":"https://api.github.com/repos/astropy/astropy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/astropy/astropy/statuses/{sha}","languages_url":"https://api.github.com/repos/astropy/astropy/languages","stargazers_url":"https://api.github.com/repos/astropy/astropy/stargazers","contributors_url":"https://api.github.com/repos/astropy/astropy/contributors","subscribers_url":"https://api.github.com/repos/astropy/astropy/subscribers","subscription_url":"https://api.github.com/repos/astropy/astropy/subscription","commits_url":"https://api.github.com/repos/astropy/astropy/commits{/sha}","git_commits_url":"https://api.github.com/repos/astropy/astropy/git/commits{/sha}","comments_url":"https://api.github.com/repos/astropy/astropy/comments{/number}","issue_comment_url":"https://api.github.com/repos/astropy/astropy/issues/comments{/number}","contents_url":"https://api.github.com/repos/astropy/astropy/contents/{+path}","compare_url":"https://api.github.com/repos/astropy/astropy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/astropy/astropy/merges","archive_url":"https://api.github.com/repos/astropy/astropy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/astropy/astropy/downloads","issues_url":"https://api.github.com/repos/astropy/astropy/issues{/number}","pulls_url":"https://api.github.com/repos/astropy/astropy/pulls{/number}","milestones_url":"https://api.github.com/repos/astropy/astropy/milestones{/number}","notifications_url":"https://api.github.com/repos/astropy/astropy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/astropy/astropy/labels{/name}","releases_url":"https://api.github.com/repos/astropy/astropy/releases{/id}","deployments_url":"https://api.github.com/repos/astropy/astropy/deployments","created_at":"2011-07-21T01:33:49Z","updated_at":"2018-07-13T17:03:40Z","pushed_at":"2018-07-13T20:06:40Z","git_url":"git://github.com/astropy/astropy.git","ssh_url":"git@github.com:astropy/astropy.git","clone_url":"https://github.com/astropy/astropy.git","svn_url":"https://github.com/astropy/astropy","homepage":"www.astropy.org","size":72360,"stargazers_count":1632,"watchers_count":1632,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":890,"mirror_url":null,"archived":false,"open_issues_count":905,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":890,"open_issues":905,"watchers":1632,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/astropy/astropy/pulls/7652"},"html":{"href":"https://github.com/astropy/astropy/pull/7652"},"issue":{"href":"https://api.github.com/repos/astropy/astropy/issues/7652"},"comments":{"href":"https://api.github.com/repos/astropy/astropy/issues/7652/comments"},"review_comments":{"href":"https://api.github.com/repos/astropy/astropy/pulls/7652/comments"},"review_comment":{"href":"https://api.github.com/repos/astropy/astropy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/astropy/astropy/pulls/7652/commits"},"statuses":{"href":"https://api.github.com/repos/astropy/astropy/statuses/7df7479e220916dec7a701c5c6ef7e85c4a1bbe7"}},"author_association":"CONTRIBUTOR","merged":false,"mergeable":null,"rebaseable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"maintainer_can_modify":true,"commits":1,"additions":96,"deletions":1,"changed_files":4}}
{"actor":{"display_login":"mhvk"}}