{"action":"created","issue":{"url":"https://api.github.com/repos/astropy/astropy/issues/3922","labels_url":"https://api.github.com/repos/astropy/astropy/issues/3922/labels{/name}","comments_url":"https://api.github.com/repos/astropy/astropy/issues/3922/comments","events_url":"https://api.github.com/repos/astropy/astropy/issues/3922/events","html_url":"https://github.com/astropy/astropy/pull/3922","id":93548811,"number":3922,"title":"Quantity operations call `__array_finalize__` too often?","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},"labels":[{"url":"https://api.github.com/repos/astropy/astropy/labels/Affects-dev","name":"Affects-dev","color":"eb6420"},{"url":"https://api.github.com/repos/astropy/astropy/labels/Effort-medium","name":"Effort-medium","color":"fef2c0"},{"url":"https://api.github.com/repos/astropy/astropy/labels/Low%20Priority","name":"Low Priority","color":"cccccc"},{"url":"https://api.github.com/repos/astropy/astropy/labels/Package-expert","name":"Package-expert","color":"bfe5bf"},{"url":"https://api.github.com/repos/astropy/astropy/labels/Performance","name":"Performance","color":"bfe5bf"},{"url":"https://api.github.com/repos/astropy/astropy/labels/units","name":"units","color":"c7def8"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-07-07T14:49:54Z","updated_at":"2015-07-09T14:17:04Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/astropy/astropy/pulls/3922","html_url":"https://github.com/astropy/astropy/pull/3922","diff_url":"https://github.com/astropy/astropy/pull/3922.diff","patch_url":"https://github.com/astropy/astropy/pull/3922.patch"},"body":"This is mostly a reminder that while trying to test speed issues in #3898, we found that `Quantity.__array_finalize__` seems to be called more often than necessary. Eg.,\r\n```\r\nIn [2]: q = np.arange(10)*u.m\r\nIn __array_finalize__; self, obj= <Quantity [ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9.] (Unit not initialised)> array([ 0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9.])\r\n\r\nIn [3]: q[2:3]\r\nIn __array_finalize__; self, obj= <Quantity [ 2.] (Unit not initialised)> <Quantity [ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9.] m>\r\nIn __array_finalize__; self, obj= <Quantity [ 2.] (Unit not initialised)> <Quantity [ 2.] m>\r\nIn __array_finalize__; self, obj= <Quantity [ 2.] m> <Quantity [ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9.] m>\r\nOut[3]: <Quantity [ 2.] m>\r\nIn [6]: np.square(q)\r\nIn __array_finalize__; self, obj= <Quantity [  6.94677988e-310,  2.34355731e-316,  6.94677779e-310,\r\n             6.94677779e-310,  6.94677779e-310,  6.94677779e-310,\r\n             6.94677779e-310,  6.94677779e-310,  6.94677779e-310,\r\n             6.94677781e-310] (Unit not initialised)> array([  6.94677988e-310,   2.34355731e-316,   6.94677779e-310,\r\n         6.94677779e-310,   6.94677779e-310,   6.94677779e-310,\r\n         6.94677779e-310,   6.94677779e-310,   6.94677779e-310,\r\n         6.94677781e-310])\r\nIn __array_finalize__; self, obj= <Quantity [  6.94677988e-310,  2.34355731e-316,  6.94677779e-310,\r\n             6.94677779e-310,  6.94677779e-310,  6.94677779e-310,\r\n             6.94677779e-310,  6.94677779e-310,  6.94677779e-310,\r\n             6.94677781e-310] (Unit not initialised)> <Quantity [ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9.] m>\r\n```\r\nIt seems likely this can be sped up a little."},"comment":{"url":"https://api.github.com/repos/astropy/astropy/issues/comments/119997613","html_url":"https://github.com/astropy/astropy/pull/3922#issuecomment-119997613","issue_url":"https://api.github.com/repos/astropy/astropy/issues/3922","id":119997613,"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},"created_at":"2015-07-09T14:17:04Z","updated_at":"2015-07-09T14:17:04Z","body":"OK, made a few simple changes that reduce the number of calls to `__array_finalize__`. In the process, also found a bug, where raising a quantity to a `Fraction` resulted in an object dtype:\r\n```\r\nIn [4]: q = (25 * u.m**2) \r\n\r\nIn [5]: q ** Fraction(1,2)\r\nOut[5]: <Quantity 5.0 m>\r\n\r\nIn [6]: q2 = q ** Fraction(1,2)\r\n\r\nIn [7]: q2.dtype\r\nOut[7]: dtype('O')\r\n```"}}