[Numpy-discussion] subclassing ndarray subtleties??
chris.barker at noaa.gov
Tue May 22 16:47:48 EDT 2012
On Tue, May 22, 2012 at 1:07 PM, Dan Goodman <dg.gmane at thesamovar.net> wrote:
> I think it would be useful to have an example of a completely
> 'correctly' subclassed ndarray that handles all of these issues that
> people could use as a template when they want to subclass ndarray.
I think this is by definition impossible -- if you are subclassing it,
you are changing its behavior is *some* way, which way will determine
how you want it it behave under all the various conditions that an
array may encounter. So there is no subclass that handles all these
issues, nor is there any pre-defined definition for correct.
My personal use for subclassing has been to plug in a new object into
code that was currently using a regular old numpy array -- in that
case, all it needed to handle were the use-cases it was already being
used in -- so running my test code was all I needed. But if I were
startting from scratch, I'd probably use the "has a" rather than the
"is a" OO model.
Christopher Barker, Ph.D.
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
More information about the NumPy-Discussion