{"action":"created","issue":{"url":"https://api.github.com/repos/numpy/numpy/issues/4586","labels_url":"https://api.github.com/repos/numpy/numpy/issues/4586/labels{/name}","comments_url":"https://api.github.com/repos/numpy/numpy/issues/4586/comments","events_url":"https://api.github.com/repos/numpy/numpy/issues/4586/events","html_url":"https://github.com/numpy/numpy/pull/4586","id":30897875,"number":4586,"title":"ENH: Let MaskedArray getter, setter respect baseclass overrides","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":null,"comments":15,"created_at":"2014-04-04T21:52:11Z","updated_at":"2015-03-28T05:53:53Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/numpy/numpy/pulls/4586","html_url":"https://github.com/numpy/numpy/pull/4586","diff_url":"https://github.com/numpy/numpy/pull/4586.diff","patch_url":"https://github.com/numpy/numpy/pull/4586.patch"},"body":"As is, `MaskedArray` uses explicity calls to `ndarray.__setitem__(self.data, indx, value)` and `ndarray.__getitem__(self.data, indx)` to access elements of its baseclass. This PR uses `self.data[indx]` instead, so that possible overrides of `__getitem__` and `__setitem__` are respected.\r\n\r\nThis is particularly useful for astropy's `Quantity` ndarray subclass, since it should check that anything written to it has the correct unit, and associate units for anything gotten from it.\r\n\r\n(Note: this includes #4585, as otherwise some of the tests would fail; I'll rebase once that is in.)"},"comment":{"url":"https://api.github.com/repos/numpy/numpy/issues/comments/87168086","html_url":"https://github.com/numpy/numpy/pull/4586#issuecomment-87168086","issue_url":"https://api.github.com/repos/numpy/numpy/issues/4586","id":87168086,"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},"created_at":"2015-03-28T05:53:53Z","updated_at":"2015-03-28T05:53:53Z","body":"@ahaldane - when I wrote this PR I was mercilessly unaware of the pitfalls of matrices!  Your example indeed shows a big one: either the masked version operates differently from the unmasked one, or the mask gets out of whack.\r\n\r\nI think there are two parts to a possible solution.  First would be for `MaskedArray` not to define `__mul__`, etc., but purely work at the `ufunc` level (i.e., with `__array_prepare__`, `__array_wrap__`, or, better, `__numpy_ufunc__`). Second to ensure that it takes on the methods what is being masked, so that the methods of the enclosed class are available. Then, when one calls `mx * mx`, this leads to `Matrix.__mul__`, which calls `np.dot`, which will first be passed through `MaskedArray.__numpy_ufunc__`, and there the mask can be dealt with, with the proper `ufunc` in hand.\r\n\r\nBut I'm far from sure this would work for all cases; in end, my sense would be that in terms of broadcasting, etc., `MaskedArray` should simply be able to assume that a subclass behaves like an `ndarray`. But obviously it does not currently, so this would break backwards compatibility.\r\n\r\nNow on your specific example, I should add that my impression was that the matrix class has become such a problem that most people simply do not use it. Indeed, in python3.5 a new operator `@` and associated `__matmul__` method will be specifically introduced to make matrix operations with regular arrays easier (see http://legacy.python.org/dev/peps/pep-0465/).\r\n"}}