[SciPy-User] subclassing ndarray : i want slice to return > ndarray, not subclass
M Daoust
m_daoust at hotmail.com
Thu May 24 06:40:25 EDT 2012
> > Subclassing ndarray is a very tricky business -- I did it once and
> > regretted having done it for years, because there's so much you can't do
> > etc.. You're almost certainly better off with embedding an array as an
> > attribute, and then forward properties etc. to it.
>
> Yes, it's almost always the wrong thing...
I've sub-classes numpy.ndarray in some of my personal code, so I'm just
hoping to understand why this is the wrong choice before I dig the
hole any deeper.
So it's only wrong because it's hard to do right, and you can't do certain things? (which things?)
If you want a object to act mostly like a numpy.ndarray, making a sub-class *should* be the right answer.
Because isn't forwarding lookups to a wrapped class just a re-implementation of the sub-classing mechanism?
Isn't it also tricky to get that "wrapping subclassing" right?
If you're going to sub-class something, it would be nice to use the built in sub-class machinery, for clarity... etc...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20120524/348c491c/attachment.html>
More information about the SciPy-User
mailing list