{"action":"created","issue":{"url":"https://api.github.com/repos/numpy/numpy/issues/3907","labels_url":"https://api.github.com/repos/numpy/numpy/issues/3907/labels{/name}","comments_url":"https://api.github.com/repos/numpy/numpy/issues/3907/comments","events_url":"https://api.github.com/repos/numpy/numpy/issues/3907/events","html_url":"https://github.com/numpy/numpy/pull/3907","id":20922434,"number":3907,"title":"BUG allow subclasses in MaskedArray ufuncs -- for non-ndarray _data","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},"labels":[{"url":"https://api.github.com/repos/numpy/numpy/labels/component:%20numpy.ma","name":"component: numpy.ma","color":"ff0000"},{"url":"https://api.github.com/repos/numpy/numpy/labels/Maintenance","name":"Maintenance","color":"02e10c"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/numpy/numpy/milestones/35","html_url":"https://github.com/numpy/numpy/milestones/1.10.0%20release","labels_url":"https://api.github.com/repos/numpy/numpy/milestones/35/labels","id":1055363,"number":35,"title":"1.10.0 release","description":"Marker for PRs that should go into Numpy 1.10.1.","creator":{"login":"charris","id":77272,"avatar_url":"https://avatars.githubusercontent.com/u/77272?v=3","gravatar_id":"","url":"https://api.github.com/users/charris","html_url":"https://github.com/charris","followers_url":"https://api.github.com/users/charris/followers","following_url":"https://api.github.com/users/charris/following{/other_user}","gists_url":"https://api.github.com/users/charris/gists{/gist_id}","starred_url":"https://api.github.com/users/charris/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/charris/subscriptions","organizations_url":"https://api.github.com/users/charris/orgs","repos_url":"https://api.github.com/users/charris/repos","events_url":"https://api.github.com/users/charris/events{/privacy}","received_events_url":"https://api.github.com/users/charris/received_events","type":"User","site_admin":false},"open_issues":8,"closed_issues":42,"state":"open","created_at":"2015-04-07T00:02:10Z","updated_at":"2015-06-15T20:16:57Z","due_on":null,"closed_at":null},"comments":29,"created_at":"2013-10-13T06:04:37Z","updated_at":"2015-06-16T21:53:08Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/numpy/numpy/pulls/3907","html_url":"https://github.com/numpy/numpy/pull/3907","diff_url":"https://github.com/numpy/numpy/pull/3907.diff","patch_url":"https://github.com/numpy/numpy/pull/3907.patch"},"body":"This is a follow-on to #3900, making two furthe changes to tryto reach the ultimate goal of `MaskedArray` behaving sensibly for subclasses. \r\n1. Ensure that for two-argument ufunc's, the data in the subclass are no longer converted to `ndarray`; rather, a possible subclass is kept. This is particularly relevant for my work on a `MaskedQuantity` class, where `_data` contains a `Quantity` which has not just a value (the ndarray) but also a unit.\r\n2. Avoid the creation of `object` arrays, so that non-array Classes with an `__array_priority__` set and with a reverse method defined properly lead to `NotImplemented` (i.e., making the behaviour match that of regular arrays).\r\n\r\nIn order for this to work, I\r\n- removed `subok=False` in the `getdata` calls in the two `BinaryOperation` classes\r\n- slightly changed the method used to keep previous values when they are masked, including allowing this to fail (e.g., when I multiply two masked quantities in meters, the result is an area, and hence it is senseless to keep the original values, and quantities raise an appropriate UnitError). (Without this, the matrix subclass tests would not pass).\r\n- slightly changed the order, with result masks only calculated if the primary calculation succeeded.\r\n- slightly changed `getdata` to avoid the creation of `object` arrays, and `getmaskedarray` to deal with the consequences.\r\n\r\nI also added a test case, which perhaps best makes clear why this is useful. \r\n\r\nCC @charris -- I consider the above a correction of a bug, but realise this is subjective; it could also be ENH, even though the API does not change. It would be wonderful if this could still make it to 1.8."},"comment":{"url":"https://api.github.com/repos/numpy/numpy/issues/comments/112579050","html_url":"https://github.com/numpy/numpy/pull/3907#issuecomment-112579050","issue_url":"https://api.github.com/repos/numpy/numpy/issues/3907","id":112579050,"user":{"login":"charris","id":77272,"avatar_url":"https://avatars.githubusercontent.com/u/77272?v=3","gravatar_id":"","url":"https://api.github.com/users/charris","html_url":"https://github.com/charris","followers_url":"https://api.github.com/users/charris/followers","following_url":"https://api.github.com/users/charris/following{/other_user}","gists_url":"https://api.github.com/users/charris/gists{/gist_id}","starred_url":"https://api.github.com/users/charris/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/charris/subscriptions","organizations_url":"https://api.github.com/users/charris/orgs","repos_url":"https://api.github.com/users/charris/repos","events_url":"https://api.github.com/users/charris/events{/privacy}","received_events_url":"https://api.github.com/users/charris/received_events","type":"User","site_admin":false},"created_at":"2015-06-16T21:53:08Z","updated_at":"2015-06-16T21:53:08Z","body":"Hmm, this test failure looks potentially real (but maybe not repeatable). I'm going to restart the test but keeping this for reference. The `numpy/ma/testutils.py` is the only thing that looks related.\r\n```\r\nFAIL: test_io.test_load_refcount\r\n\r\n----------------------------------------------------------------------\r\n\r\nTraceback (most recent call last):\r\n\r\n  File \"/home/travis/build/numpy/numpy/builds/venv/lib/python2.7/site-packages/nose/case.py\", line 197, in runTest\r\n\r\n    self.test(*self.arg)\r\n\r\n  File \"/home/travis/build/numpy/numpy/builds/venv/lib/python2.7/site-packages/numpy/lib/tests/test_io.py\", line 1920, in test_load_refcount\r\n\r\n    assert_equal(n_before, n_after)\r\n\r\n  File \"/home/travis/build/numpy/numpy/builds/venv/lib/python2.7/site-packages/numpy/ma/testutils.py\", line 100, in assert_equal\r\n\r\n    raise AssertionError(msg)\r\n\r\nAssertionError: \r\n\r\nItems are not equal:\r\n\r\n ACTUAL: 55930\r\n\r\n DESIRED: 55911\r\n```"}}