[Numpy-discussion] Changing MaskedArray.squeeze() to never return masked
ben.v.root at gmail.com
Tue Jul 18 09:52:08 EDT 2017
This sort of change seems very similar to the np.diag() change a few years
ago. Are there lessons we could learn from then that we could apply to here?
Why would the returned view not be a masked array?
On Tue, Jul 18, 2017 at 9:37 AM, Eric Wieser <wieser.eric+numpy at gmail.com>
> When using ndarray.squeeze, a view is returned, which means you can do
> the follow (somewhat-contrived) operation:
> >>> def fill_contrived(a):
> a.squeeze()[...] = 2
> return a
> >>> fill_contrived(np.array())
> However, when tried with a masked array, this can fail, breaking liskov
> >>> fill_contrived(np.ma.array(, mask=[True]))
> MaskError: Cannot alter the masked element.
> This fails because squeeze breaks the contract of returning a view,
> instead deciding sometimes to return masked.
> There is a patch that fixes this in gh-9432
> <https://github.com/numpy/numpy/pull/9432> - however, by necessity it
> breaks any existing code that uses m_arr.squeeze() is np.ma.masked.
> Is this too breaking a change?
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion