![](https://secure.gravatar.com/avatar/97c543aca1ac7bbcfb5279d0300c8330.jpg?s=120&d=mm&r=g)
On Fri, Nov 9, 2018 at 4:59 PM, Stephan Hoyer <shoyer@gmail.com> wrote:
On Fri, Nov 9, 2018 at 6:46 PM Nathaniel Smith <njs@pobox.com> 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 specifically do masked arrays violate Liskov? In most cases shouldn't they work the same as base numpy arrays, except with operations keeping track of masks?
Since many operations silently skip over masked values, the computation semantics are different. For example, in a regular array, sum()/size() == mean(), but with a masked array these are totally different operations. So if you have code that was written for regular arrays, but pass in a masked array, there's a solid chance that it will silently return nonsensical results. (This is why it's better for NAs to propagate by default.) -n -- Nathaniel J. Smith -- https://vorpus.org