{"action":"closed","issue":{"url":"https://api.github.com/repos/numba/numba/issues/704","labels_url":"https://api.github.com/repos/numba/numba/issues/704/labels{/name}","comments_url":"https://api.github.com/repos/numba/numba/issues/704/comments","events_url":"https://api.github.com/repos/numba/numba/issues/704/events","html_url":"https://github.com/numba/numba/issues/704","id":40489417,"number":704,"title":"casting issues","user":{"login":"gdementen","id":832092,"avatar_url":"https://avatars.githubusercontent.com/u/832092?v=3","gravatar_id":"","url":"https://api.github.com/users/gdementen","html_url":"https://github.com/gdementen","followers_url":"https://api.github.com/users/gdementen/followers","following_url":"https://api.github.com/users/gdementen/following{/other_user}","gists_url":"https://api.github.com/users/gdementen/gists{/gist_id}","starred_url":"https://api.github.com/users/gdementen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gdementen/subscriptions","organizations_url":"https://api.github.com/users/gdementen/orgs","repos_url":"https://api.github.com/users/gdementen/repos","events_url":"https://api.github.com/users/gdementen/events{/privacy}","received_events_url":"https://api.github.com/users/gdementen/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2014-08-18T13:47:47Z","updated_at":"2015-03-05T12:45:28Z","closed_at":"2015-03-05T12:45:28Z","body":"TL;DR: casting in nopython mode fails; casting using numba types produces bad types\r\n\r\n```python\r\nimport numpy as np\r\nfrom numba import jit, float64\r\n\r\ndef cast1(a):\r\n    return np.float64(a)\r\n\r\ndef cast2(a):\r\n    return float64(a)\r\n\r\ncast1_nb1 = jit(cast1)\r\n# fails at compile time\r\ncast1_nb2 = jit(cast1, nopython=True)\r\n\r\n# I am unsure types in numba are intended to be used as casting functions\r\n# but it seems pretty natural to me to do that. These both compile\r\n# and run but return python float instead of np.float64\r\ncast2_nb1 = jit(cast2)\r\ncast2_nb2 = jit(cast2, nopython=True)\r\n\r\na = np.int32(10)\r\nr = cast1(a)\r\nr2 = cast2(a)\r\nassert r2 == r and type(r2) == type(r)\r\n\r\nfor i, func in enumerate((cast1_nb1, cast1_nb2,\r\n                          cast2_nb1, cast2_nb2)):\r\n    print(i)\r\n    ri = func(a)\r\n    assert ri == r, \"%f != %f\" % (ri, r)\r\n    assert type(ri) == type(r), \"%s != %s\" % (type(ri), type(r))\r\n```"}}