On Monday 04 August 2008 14:16:33 Darren Dale wrote: > Hi Jarrod, > > I was wondering if someone knowledgeable would please look into the > behavior of concatenate() with subclasses of ndarray.
Darren, I ran into similar problems when I started working on numpy.ma and scikits.timeseries, and I remember having conversations with Bryce Hendrix of Enthought about that on this very list. I think you have a problem in `NDQuantities.__array_finalize__`: you don't initialize `._units` if `obj` doesn't have a `_units`. At least, you should use something like self._units = getattr(obj, '_units', None), which will set `._units` to None if `obj` is not a NDQuantities, and will also ensure that your NDQuantities array always have a ._units attribute. In other words, if I take a view of a ndarray as a NDQuantities, I should have a _units defined by default (None being the most appropriate in that case). About concatenation: In a lot of cases, concatenate requires some tweaking. In scikits.timeseries, we have to decide what to do when the series being concatenated overlap. In your case, you have to decide what to do when concatenating 2 arrays A & B, for example: * if A & B have the same unit, keep it * If A (B) doesn't have a unit, keep the unit of B (A) * If the units of A and B are compatible, convert one to the other * If the units are incompatible, raise an exception. What I suggest is to implement your own concatenate: check the units, concatenate the arrays as regular ndarrays, take a view of the result, modify the unit of the result accordingly. About subclassing: * You may want to check the cookbook: http://www.scipy.org/Subclasses * You may also want to check other ndarray subclasses, such as MaskedArray, TimeSeries (</pushing product>) for some implementation details. * You may also want add your own experience on http://www.scipy.org/Subclasses, so that we don't lose it. Drop me a line offlist if you'd like, I'd be happy to help (depending on the time at hand). Cheers. P. _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion