[Numpy-discussion] asarray/anyarray; matrix/subclass
Marten van Kerkwijk
m.h.vankerkwijk at gmail.com
Sat Nov 10 17:50:56 EST 2018
On Sat, Nov 10, 2018 at 5:39 PM Stephan Hoyer <shoyer at gmail.com> wrote:
> On Sat, Nov 10, 2018 at 2:22 PM Hameer Abbasi <einstein.edison at gmail.com>
>> To summarize, I think these are our options:
>> 1. Change the behavior of np.anyarray() to check for an __anyarray__()
>> protocol. Change np.matrix.__anyarray__() to return a base numpy array
>> (this is a minor backwards compatibility break, but probably for the best).
>> Start issuing a FutureWarning for any MaskedArray operations that violate
>> Liskov and add a skipna argument that in the future will default to
>> 2. Introduce a new coercion function, e.g., np.duckarray(). This is the
>> easiest option because we don't need to cleanup NumPy's existing ndarray
>> My vote is still for 1. I don’t have an issue for PyData/Sparse depending
>> on recent-ish NumPy versions — It’ll need a lot of the recent protocols
>> anyway, although I could be convinced otherwise if major package devs
>> (scikits, SciPy, Dask) were to weigh in and say they’ll jump on it (which
>> seems unlikely given SciPy’s policy to support old NumPy versions).
> I agree that option (1) is fine for PyData/sparse. The bigger issue is
> that this change should be conditional on making breaking changes (at least
> raising FutureWarning for now) to np.ma.MaskedArray.
Might be good to try before worrying too much - MaskedArray already
overrides *a lot*; it is not at all obvious to me that things wouldn't
"just work" if we bulk-replaced `asarray` with `asanyarray`. And with
`__array_function__` we now have the option to fix code paths that do not
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion