{"action":"closed","issue":{"url":"https://api.github.com/repos/numpy/numpy/issues/2346","repository_url":"https://api.github.com/repos/numpy/numpy","labels_url":"https://api.github.com/repos/numpy/numpy/issues/2346/labels{/name}","comments_url":"https://api.github.com/repos/numpy/numpy/issues/2346/comments","events_url":"https://api.github.com/repos/numpy/numpy/issues/2346/events","html_url":"https://github.com/numpy/numpy/issues/2346","id":7731323,"number":2346,"title":"recfunctions.append_fields fails on arrays containing objects (Trac #1751)","user":{"login":"numpy-gitbot","id":1955252,"avatar_url":"https://avatars0.githubusercontent.com/u/1955252?v=4","gravatar_id":"","url":"https://api.github.com/users/numpy-gitbot","html_url":"https://github.com/numpy-gitbot","followers_url":"https://api.github.com/users/numpy-gitbot/followers","following_url":"https://api.github.com/users/numpy-gitbot/following{/other_user}","gists_url":"https://api.github.com/users/numpy-gitbot/gists{/gist_id}","starred_url":"https://api.github.com/users/numpy-gitbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/numpy-gitbot/subscriptions","organizations_url":"https://api.github.com/users/numpy-gitbot/orgs","repos_url":"https://api.github.com/users/numpy-gitbot/repos","events_url":"https://api.github.com/users/numpy-gitbot/events{/privacy}","received_events_url":"https://api.github.com/users/numpy-gitbot/received_events","type":"User","site_admin":false},"labels":[{"id":6359214,"url":"https://api.github.com/repos/numpy/numpy/labels/00%20-%20Bug","name":"00 - Bug","color":"fef2c0","default":false},{"id":16917082,"url":"https://api.github.com/repos/numpy/numpy/labels/component:%20numpy.lib","name":"component: numpy.lib","color":"009800","default":false},{"id":16915544,"url":"https://api.github.com/repos/numpy/numpy/labels/priority:%20normal","name":"priority: normal","color":"ff0000","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/numpy/numpy/milestones/9","html_url":"https://github.com/numpy/numpy/milestone/9","labels_url":"https://api.github.com/repos/numpy/numpy/milestones/9/labels","id":198265,"number":9,"title":"NumPy 2.0","description":null,"creator":{"login":"numpy-gitbot","id":1955252,"avatar_url":"https://avatars0.githubusercontent.com/u/1955252?v=4","gravatar_id":"","url":"https://api.github.com/users/numpy-gitbot","html_url":"https://github.com/numpy-gitbot","followers_url":"https://api.github.com/users/numpy-gitbot/followers","following_url":"https://api.github.com/users/numpy-gitbot/following{/other_user}","gists_url":"https://api.github.com/users/numpy-gitbot/gists{/gist_id}","starred_url":"https://api.github.com/users/numpy-gitbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/numpy-gitbot/subscriptions","organizations_url":"https://api.github.com/users/numpy-gitbot/orgs","repos_url":"https://api.github.com/users/numpy-gitbot/repos","events_url":"https://api.github.com/users/numpy-gitbot/events{/privacy}","received_events_url":"https://api.github.com/users/numpy-gitbot/received_events","type":"User","site_admin":false},"open_issues":23,"closed_issues":109,"state":"closed","created_at":"2012-10-19T15:11:31Z","updated_at":"2017-09-09T20:45:29Z","due_on":null,"closed_at":"2015-03-21T02:13:20Z"},"comments":4,"created_at":"2012-10-19T22:23:20Z","updated_at":"2017-09-09T20:45:29Z","closed_at":"2017-09-09T20:45:29Z","author_association":"NONE","body":"_Original ticket http://projects.scipy.org/numpy/ticket/1751 on 2011-02-28 by trac user aickley, assigned to unknown._\n\nThe problem is that append_fields calls array.view() which does not accept arrays containing objects (See [http://projects.scipy.org/numpy/ticket/674])\n\nTest case (to include in numpy/lib/tests/recfunctions.py):\n\n```\nclass TestAppendFieldsObj(TestCase):\n    \"\"\"\n    Test append_fields with arrays containing objects\n    \"\"\"\n    def setUp(self):\n        from datetime import date\n        self.data = dict(obj=date(2000, 1, 1))\n\n    def test_append_to_objects(self):\n        \"Test append_fields when the base array contains objects\"\n        obj = self.data['obj']\n        x = np.array([(obj, 1.), (obj, 2.)], dtype=[('A', object), ('B', float)])\n        y = np.array([10, 20], dtype=int)\n        test = append_fields(x, 'C', data=y, usemask=False)\n        control = np.array([(obj, 1.0, 10), (obj, 2.0, 20)],\n                           dtype=[('A', object), ('B', float), ('C', int)])\n        assert_equal(test, control)\n    #\n    def test_append_with_objects(self):\n        \"Test append_fields when the appended data contains objects\"\n        obj = self.data['obj']\n        x = np.array([(10, 1.), (20, 2.)], dtype=[('A', int), ('B', float)])\n        y = np.array([obj, obj], dtype=object)\n        test = append_fields(y, 'C', data=y, dtypes=object, usemask=False)\n        control = np.array([(10, 1.0, obj), (20, 2.0, obj)],\n                           dtype=[('A', int), ('B', float), ('C', object)])\n        assert_equal(test, control)\n\n\n\n\n\n\n======================================================================\nERROR: Test append_fields when the base array contains objects\n----------------------------------------------------------------------\nTraceback (most recent call last):\n  File \"/home/kolpakov/lib/python2.6/site-packages/numpy/lib/tests/test_recfunctions.py\", line 406, in test_append_to_objects\n    test = append_fields(x, 'C', data=y, usemask=False)\n  File \"/home/kolpakov/lib/python2.6/site-packages/numpy/lib/recfunctions.py\", line 629, in append_fields\n    base = merge_arrays(base, usemask=usemask, fill_value=fill_value)\n  File \"/home/kolpakov/lib/python2.6/site-packages/numpy/lib/recfunctions.py\", line 399, in merge_arrays\n    return seqarrays.view(dtype=seqdtype, type=seqtype)\nTypeError: Cannot change data-type for object array.\n\n======================================================================\nERROR: Test append_fields when the appended data contains objects\n----------------------------------------------------------------------\nTraceback (most recent call last):\n  File \"/home/kolpakov/lib/python2.6/site-packages/numpy/lib/tests/test_recfunctions.py\", line 416, in test_append_with_objects\n    test = append_fields(y, 'C', data=y, dtypes=object, usemask=False)\n  File \"/home/kolpakov/lib/python2.6/site-packages/numpy/lib/recfunctions.py\", line 627, in append_fields\n    for (a, n, d) in zip(data, names, dtypes)]\nTypeError: Cannot change data-type for object array.\n\n----------------------------------------------------------------------\nRan 33 tests in 0.062s\n```\n\nRegarding the first failure, append_fields calls merge_arrays on the base array:\n\n```\nbase = merge_arrays(base, usemask=usemask, fill_value=fill_value)\n```\n\nActually this line can be completely removed without breaking existing unit tests. I don't like this call because if we are calling merge_array on a single array we are are not actually _merging_ anything, but rather  making sure that the array conforms to certain criteria. Maybe this code should be refactored out from merge_arrays...\n"}}
{"actor":{"display_login":"charris"}}