{"action":"closed","issue":{"url":"https://api.github.com/repos/pydap/pydap/issues/41","repository_url":"https://api.github.com/repos/pydap/pydap","labels_url":"https://api.github.com/repos/pydap/pydap/issues/41/labels{/name}","comments_url":"https://api.github.com/repos/pydap/pydap/issues/41/comments","events_url":"https://api.github.com/repos/pydap/pydap/issues/41/events","html_url":"https://github.com/pydap/pydap/issues/41","id":196858072,"number":41,"title":"Unexpected 'flattening' of the array when slicing on BaseProxy","user":{"login":"taeold","id":14897098,"avatar_url":"https://avatars.githubusercontent.com/u/14897098?v=3","gravatar_id":"","url":"https://api.github.com/users/taeold","html_url":"https://github.com/taeold","followers_url":"https://api.github.com/users/taeold/followers","following_url":"https://api.github.com/users/taeold/following{/other_user}","gists_url":"https://api.github.com/users/taeold/gists{/gist_id}","starred_url":"https://api.github.com/users/taeold/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/taeold/subscriptions","organizations_url":"https://api.github.com/users/taeold/orgs","repos_url":"https://api.github.com/users/taeold/repos","events_url":"https://api.github.com/users/taeold/events{/privacy}","received_events_url":"https://api.github.com/users/taeold/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-12-21T06:36:53Z","updated_at":"2017-01-03T19:31:24Z","closed_at":"2017-01-03T19:31:24Z","body":"Hello,\r\n\r\nI notice the following (unexpected) behavior when using pydap to accessing n-dimensional variable:\r\n\r\n```\r\nIn [1]: import pydap.client\r\n\r\nIn [2]: ds = pydap.client.open_url('http://test.opendap.org/opendap/hyrax/data/nc/123.nc')\r\n\r\nIn [3]: ds\r\nOut[3]: <DatasetType with children 'bears', 'order', 'shot', 'aloan', 'cross', 'i', 'j', 'l'>\r\n\r\nIn [4]: ds.bears\r\nOut[4]: <GridType with array 'bears' and maps 'i', 'j'>\r\n\r\nIn [5]: ds.bears.array\r\nOut[5]: <BaseType with data BaseProxy('http://test.opendap.org/opendap/hyrax/data/nc/123.nc', 'bears.bears', dtype('S128'), (2, 3), (slice(None, None, None), slice(None, None, None)))>\r\n\r\nIn [6]: ds.bears.array.shape\r\nOut[6]: (2, 3)\r\n\r\n## slicing the array flattens the output array\r\nIn [7]: ds.bears.array[:]\r\nOut[7]:\r\narray([u'ind', u'ist', u'ing', u'uis', u'hab', u'le'],\r\n      dtype='<U3')\r\n\r\nIn [8]: ds.bears.array[:].shape\r\nOut[8]: (6,)\r\n\r\n## And this won't work?\r\nIn [9]: np.asarray(ds.bears.array)\r\n---------------------------------------------------------------------------\r\nValueError                                Traceback (most recent call last)\r\n<ipython-input-8-5da01e73285e> in <module>()\r\n----> 1 np.asarray(ds.bears.array)\r\n\r\n/Users/daniel.lee/anaconda/envs/pydap/lib/python2.7/site-packages/numpy/core/numeric.pyc in asarray(a, dtype, order)\r\n    480\r\n    481     \"\"\"\r\n--> 482     return array(a, dtype, copy=False, order=order)\r\n    483\r\n    484 def asanyarray(a, dtype=None, order=None):\r\n\r\nValueError: cannot copy sequence with size 2 to array axis with dimension 6\r\n```\r\n\r\nFrom my best attempt to read over the pydap code, I find [this line](\r\nhttps://github.com/pydap/pydap/blob/master/src/pydap/handlers/dap.py#L155) suspicious:\r\n\r\n```\r\nreturn np.array([ text_type(x.decode('ascii')) for x in out ], 'S')\r\n```\r\n\r\nNamely, I think it's missing a `.reshape(shape)` call at the end.\r\n\r\n```\r\nreturn np.array([ text_type(x.decode('ascii')) for x in out ], 'S').reshape(shape)\r\n```\r\n\r\nIs what I'm suggesting here reasonable?\r\n\r\nDiscovered while investigating pydata/xarray#1174"}}
{"actor":{"display_login":"jameshiebert"}}