Re: [Numpy-discussion] asarray/anyarray; matrix/subclass

2018-11-11 Thread Stephan Hoyer
On Sat, Nov 10, 2018 at 10:45 PM Eric Firing wrote: > On 2018/11/10 12:39 PM, Stephan Hoyer wrote: > > On Sat, Nov 10, 2018 at 2:22 PM Hameer Abbasi > > wrote: > > > > To summarize, I think these are our options: > > > > 1. Change the behavior

Re: [Numpy-discussion] asarray/anyarray; matrix/subclass

2018-11-11 Thread Marten van Kerkwijk
Hi Eric, Thanks very much for the detailed response; it is good to be reminded that `MaskedArray` is used in a package that, indeed, (nearly?) all of us use! But I do think that those of us who have been trying to change MaskedArray, are generally good at making sure the tests continue to pass,

Re: [Numpy-discussion] asarray/anyarray; matrix/subclass

2018-11-10 Thread Eric Firing
On 2018/11/10 12:39 PM, Stephan Hoyer wrote: On Sat, Nov 10, 2018 at 2:22 PM Hameer Abbasi > wrote: To summarize, I think these are our options: 1. Change the behavior of np.anyarray() to check for an __anyarray__() protocol. Change

Re: [Numpy-discussion] asarray/anyarray; matrix/subclass

2018-11-10 Thread Charles R Harris
On Sat, Nov 10, 2018 at 2:15 PM Eric Wieser wrote: > > If the only way MaskedArray violates Liskov is in terms of NA skipping > aggregations by default, then this might be viable > > One of the ways to fix these liskov substitution problems is just to > introduce more base classes - for

Re: [Numpy-discussion] asarray/anyarray; matrix/subclass

2018-11-10 Thread Marten van Kerkwijk
On Sat, Nov 10, 2018 at 5:39 PM Stephan Hoyer wrote: > On Sat, Nov 10, 2018 at 2:22 PM Hameer Abbasi > wrote: > >> 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

Re: [Numpy-discussion] asarray/anyarray; matrix/subclass

2018-11-10 Thread Stephan Hoyer
On Sat, Nov 10, 2018 at 2:22 PM Hameer Abbasi wrote: > 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

Re: [Numpy-discussion] asarray/anyarray; matrix/subclass

2018-11-10 Thread Hameer Abbasi
> On Saturday, Nov 10, 2018 at 9:16 PM, Stephan Hoyer (mailto:sho...@gmail.com)> wrote: > On Sat, Nov 10, 2018 at 9:49 AM Marten van Kerkwijk > mailto:m.h.vankerkw...@gmail.com)> wrote: > > Hi Hameer, > > > > I do not think we should change `asanyarray` itself to special-case matrix; > >

Re: [Numpy-discussion] asarray/anyarray; matrix/subclass

2018-11-10 Thread Eric Wieser
> If the only way MaskedArray violates Liskov is in terms of NA skipping aggregations by default, then this might be viable One of the ways to fix these liskov substitution problems is just to introduce more base classes - for instance, if we had an `NDContainer` base class with only slicing

Re: [Numpy-discussion] asarray/anyarray; matrix/subclass

2018-11-10 Thread Stephan Hoyer
On Sat, Nov 10, 2018 at 9:49 AM Marten van Kerkwijk < m.h.vankerkw...@gmail.com> wrote: > Hi Hameer, > > I do not think we should change `asanyarray` itself to special-case > matrix; rather, we could start converting `asarray` to `asanyarray` and > solve the problems that produces for matrices in

Re: [Numpy-discussion] asarray/anyarray; matrix/subclass

2018-11-10 Thread Marten van Kerkwijk
Hi Hameer, I do not think we should change `asanyarray` itself to special-case matrix; rather, we could start converting `asarray` to `asanyarray` and solve the problems that produces for matrices in `matrix` itself (e.g., by overriding the relevant function with `__array_function__`). I think

Re: [Numpy-discussion] asarray/anyarray; matrix/subclass

2018-11-10 Thread Matti Picus
On 9/11/18 5:09 pm, Nathaniel Smith wrote: On Fri, Nov 9, 2018 at 4:59 PM, Stephan Hoyer wrote: On Fri, Nov 9, 2018 at 6:46 PM Nathaniel Smith wrote: But matrix isn't the only problem with asanyarray. np.ma also violates Liskov. No doubt there are other problematic ndarray subclasses out

Re: [Numpy-discussion] asarray/anyarray; matrix/subclass

2018-11-09 Thread Nathaniel Smith
On Fri, Nov 9, 2018 at 4:59 PM, Stephan Hoyer wrote: > On Fri, Nov 9, 2018 at 6:46 PM Nathaniel Smith wrote: >> >> But matrix isn't the only problem with asanyarray. np.ma also violates >> Liskov. No doubt there are other problematic ndarray subclasses out >> there too... > > > Please forgive my

Re: [Numpy-discussion] asarray/anyarray; matrix/subclass

2018-11-09 Thread Stephan Hoyer
On Fri, Nov 9, 2018 at 6:46 PM Nathaniel Smith wrote: > But matrix isn't the only problem with asanyarray. np.ma also violates > Liskov. No doubt there are other problematic ndarray subclasses out > there too... > Please forgive my ignorance (I don't really use mask arrays), but how

Re: [Numpy-discussion] asarray/anyarray; matrix/subclass

2018-11-09 Thread Nathaniel Smith
But matrix isn't the only problem with asanyarray. np.ma also violates Liskov. No doubt there are other problematic ndarray subclasses out there too... If we were going to try to reuse asanyarray through some deprecation mechanism, I think we'd need to deprecate allowing asanyarray to return

Re: [Numpy-discussion] asarray/anyarray; matrix/subclass

2018-11-09 Thread Stephan Hoyer
I’m still not sure I agree with the advantages of reusing asanyarray(), even if matrix did not exist. Yes, asanyarray will exist in old NumPy versions, but you can’t use it with sparse arrays anyways because it will have the wrong semantics. I expect this would be a bug magnet, with inadvertent

[Numpy-discussion] asarray/anyarray; matrix/subclass

2018-11-09 Thread Hameer Abbasi
> Begin forwarded message: > > From: Stephan Hoyer > Date: Friday, Nov 09, 2018 at 3:19 PM > To: Hameer Abbasi > Cc: Stefan van der Walt , Marten van Kerkwijk > Subject: asarray/anyarray; matrix/subclass > > This is a great discussion, but let's try to have it in public (e.g., on the > NumPy