{"action":"created","issue":{"url":"https://api.github.com/repos/astropy/astropy/issues/3046","labels_url":"https://api.github.com/repos/astropy/astropy/issues/3046/labels{/name}","comments_url":"https://api.github.com/repos/astropy/astropy/issues/3046/comments","events_url":"https://api.github.com/repos/astropy/astropy/issues/3046/events","html_url":"https://github.com/astropy/astropy/issues/3046","id":46464688,"number":3046,"title":"Cannot use unscaled integer quantities as indices","user":{"login":"bnordgren","id":976922,"avatar_url":"https://avatars.githubusercontent.com/u/976922?v=3","gravatar_id":"","url":"https://api.github.com/users/bnordgren","html_url":"https://github.com/bnordgren","followers_url":"https://api.github.com/users/bnordgren/followers","following_url":"https://api.github.com/users/bnordgren/following{/other_user}","gists_url":"https://api.github.com/users/bnordgren/gists{/gist_id}","starred_url":"https://api.github.com/users/bnordgren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bnordgren/subscriptions","organizations_url":"https://api.github.com/users/bnordgren/orgs","repos_url":"https://api.github.com/users/bnordgren/repos","events_url":"https://api.github.com/users/bnordgren/events{/privacy}","received_events_url":"https://api.github.com/users/bnordgren/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/astropy/astropy/labels/Bug","name":"Bug","color":"eb6420"},{"url":"https://api.github.com/repos/astropy/astropy/labels/Effort-low","name":"Effort-low","color":"fef2c0"},{"url":"https://api.github.com/repos/astropy/astropy/labels/Package-novice","name":"Package-novice","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":9,"created_at":"2014-10-22T01:45:40Z","updated_at":"2015-01-13T20:17:44Z","closed_at":null,"body":"I have an output from a calculation which I need to use as an index to an array. I've converted the type to int and made sure the units are \"dimensionless_unscaled\", but I keep getting a TypeError.\r\n\r\nThe below code is kind of an exemplar which directly creates a dimensionless_unscaled, integer quantity, and tries to use it as an index. I believe this should work, but it raises the same TypeError.\r\n\r\n```python\r\nimport numpy as np\r\nimport astropy.units as u\r\nx = [1,2,3,4]\r\nind = u.Quantity(np.array([0,1]), dtype=np.int, unit=u.dimensionless_unscaled)\r\nind.dtype\r\nOut[6]: dtype('int32')\r\nind.unit\r\nOut[7]: Unit(dimensionless)\r\nx[ind]\r\n---------------------------------------------------------------------------\r\nTypeError                                 Traceback (most recent call last)\r\n<ipython-input-8-0528873d532e> in <module>()\r\n----> 1 x[ind]\r\n\r\nC:\\Users\\bnordgren\\AppData\\Local\\Enthought\\Canopy\\User\\lib\\site-packages\\astropy\\units\\quantity.pyc in __index__(self)\r\n    847             return self.value.__index__()\r\n    848         except:\r\n--> 849             raise TypeError('Only integer dimensionless scalar quantities '\r\n    850                             'can be converted to a Python index')\r\n    851 \r\n\r\nTypeError: Only integer dimensionless scalar quantities can be converted to a Python index \r\nx[np.array([0,1])]\r\n---------------------------------------------------------------------------\r\nTypeError                                 Traceback (most recent call last)\r\n<ipython-input-9-c81fa8325335> in <module>()\r\n----> 1 x[np.array([0,1])]\r\n\r\nTypeError: only integer arrays with one element can be converted to an index \r\nind = u.Quantity([0,1], dtype=np.int, unit=u.dimensionless_unscaled)\r\n\r\nind.dtype\r\nOut[11]: dtype('int32')\r\n\r\nind.unit\r\nOut[12]: Unit(dimensionless)\r\n\r\nx[ind]\r\n---------------------------------------------------------------------------\r\nTypeError                                 Traceback (most recent call last)\r\n<ipython-input-13-0528873d532e> in <module>()\r\n----> 1 x[ind]\r\n\r\nC:\\Users\\bnordgren\\AppData\\Local\\Enthought\\Canopy\\User\\lib\\site-packages\\astropy\\units\\quantity.pyc in __index__(self)\r\n    847             return self.value.__index__()\r\n    848         except:\r\n--> 849             raise TypeError('Only integer dimensionless scalar quantities '\r\n    850                             'can be converted to a Python index')\r\n    851 \r\n\r\nTypeError: Only integer dimensionless scalar quantities can be converted to a Python index \r\n```"},"comment":{"url":"https://api.github.com/repos/astropy/astropy/issues/comments/69811928","html_url":"https://github.com/astropy/astropy/issues/3046#issuecomment-69811928","issue_url":"https://api.github.com/repos/astropy/astropy/issues/3046","id":69811928,"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-01-13T20:17:44Z","updated_at":"2015-01-13T20:17:44Z","body":"@bnordgren - trying to clean up things for 1.0: happy to have a better error message, but what should it be? As is, I think the problem is that you had missed \"scalar\" in the error message. What might have helped?"}}