{"action":"created","issue":{"url":"https://api.github.com/repos/numpy/numpy/issues/7312","repository_url":"https://api.github.com/repos/numpy/numpy","labels_url":"https://api.github.com/repos/numpy/numpy/issues/7312/labels{/name}","comments_url":"https://api.github.com/repos/numpy/numpy/issues/7312/comments","events_url":"https://api.github.com/repos/numpy/numpy/issues/7312/events","html_url":"https://github.com/numpy/numpy/issues/7312","id":135562814,"number":7312,"title":"np.sum with ``keepdims=True`` fails on masked_array","user":{"login":"astrofrog","id":314716,"avatar_url":"https://avatars.githubusercontent.com/u/314716?v=3","gravatar_id":"","url":"https://api.github.com/users/astrofrog","html_url":"https://github.com/astrofrog","followers_url":"https://api.github.com/users/astrofrog/followers","following_url":"https://api.github.com/users/astrofrog/following{/other_user}","gists_url":"https://api.github.com/users/astrofrog/gists{/gist_id}","starred_url":"https://api.github.com/users/astrofrog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/astrofrog/subscriptions","organizations_url":"https://api.github.com/users/astrofrog/orgs","repos_url":"https://api.github.com/users/astrofrog/repos","events_url":"https://api.github.com/users/astrofrog/events{/privacy}","received_events_url":"https://api.github.com/users/astrofrog/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-02-22T22:17:49Z","updated_at":"2016-02-22T22:27:37Z","closed_at":null,"body":"When calling ``np.sum`` on a masked array, and using the ``keepdims`` option, an error is raised:\r\n\r\n```\r\nIn [1]: import numpy as np \r\n\r\nIn [2]: np.sum(np.ma.masked_array([1,2,3],mask=[0,0,1]),keepdims=True)\r\n---------------------------------------------------------------------------\r\nTypeError                                 Traceback (most recent call last)\r\n<ipython-input-8-482ed005c74d> in <module>()\r\n----> 1 np.sum(np.ma.masked_array([1,2,3],mask=[0,0,1]),keepdims=True)\r\n\r\n/Users/tom/miniconda3/envs/production27/lib/python2.7/site-packages/numpy-1.12.0.dev0+0dbcd2f-py2.7-macosx-10.5-x86_64.egg/numpy/core/fromnumeric.pyc in sum(a, axis, dtype, out, keepdims)\r\n   1843             pass\r\n   1844         else:\r\n-> 1845             return sum(axis=axis, dtype=dtype, out=out, **kwargs)\r\n   1846     return _methods._sum(a, axis=axis, dtype=dtype,\r\n   1847                          out=out, **kwargs)\r\n\r\nTypeError: sum() got an unexpected keyword argument 'keepdims'\r\n```"},"comment":{"url":"https://api.github.com/repos/numpy/numpy/issues/comments/187417024","html_url":"https://github.com/numpy/numpy/issues/7312#issuecomment-187417024","issue_url":"https://api.github.com/repos/numpy/numpy/issues/7312","id":187417024,"user":{"login":"astrofrog","id":314716,"avatar_url":"https://avatars.githubusercontent.com/u/314716?v=3","gravatar_id":"","url":"https://api.github.com/users/astrofrog","html_url":"https://github.com/astrofrog","followers_url":"https://api.github.com/users/astrofrog/followers","following_url":"https://api.github.com/users/astrofrog/following{/other_user}","gists_url":"https://api.github.com/users/astrofrog/gists{/gist_id}","starred_url":"https://api.github.com/users/astrofrog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/astrofrog/subscriptions","organizations_url":"https://api.github.com/users/astrofrog/orgs","repos_url":"https://api.github.com/users/astrofrog/repos","events_url":"https://api.github.com/users/astrofrog/events{/privacy}","received_events_url":"https://api.github.com/users/astrofrog/received_events","type":"User","site_admin":false},"created_at":"2016-02-22T22:27:37Z","updated_at":"2016-02-22T22:27:37Z","body":"This can be triggered even without the user passing ``keepdims``:\r\n\r\n```\r\nIn [6]: x = np.ma.masked_array([1,2,np.nan],mask=[0,0,1])\r\n\r\nIn [7]: np.nanvar(x)\r\n---------------------------------------------------------------------------\r\nTypeError                                 Traceback (most recent call last)\r\n<ipython-input-7-ede4d9457a87> in <module>()\r\n----> 1 np.nanvar(x)\r\n\r\n/Users/tom/miniconda3/envs/production27/lib/python2.7/site-packages/numpy-1.12.0.dev0+0dbcd2f-py2.7-macosx-10.5-x86_64.egg/numpy/lib/nanfunctions.py in nanvar(a, axis, dtype, out, ddof, keepdims)\r\n   1182         # the reason that it drops the keepdims kwarg is to force keepdims=True\r\n   1183         # so this used to work by serendipity.\r\n-> 1184         cnt = np.sum(~mask, axis=axis, dtype=np.intp, keepdims=_keepdims)\r\n   1185         avg = np.sum(arr, axis=axis, dtype=dtype, keepdims=_keepdims)\r\n   1186         avg = _divide_by_count(avg, cnt)\r\n\r\n/Users/tom/miniconda3/envs/production27/lib/python2.7/site-packages/numpy-1.12.0.dev0+0dbcd2f-py2.7-macosx-10.5-x86_64.egg/numpy/core/fromnumeric.pyc in sum(a, axis, dtype, out, keepdims)\r\n   1841         print(type(a))\r\n   1842         sum = a.sum\r\n-> 1843         return sum(axis=axis, dtype=dtype, out=out, **kwargs)\r\n   1844     return _methods._sum(a, axis=axis, dtype=dtype,\r\n   1845                          out=out, **kwargs)\r\n\r\nTypeError: sum() got an unexpected keyword argument 'keepdims'\r\n```"}}