On Tuesday 27 March 2007 20:08:04 Bryce Hendrix wrote:
We have a class which is a subclass of ndarray which defines
__array_finalize__ to add an attribute. The class looks something like
this:
Ahah, we ran into this problem a few months ago:
You should not initialize your "units" attribute in the __new__ method, as
it's not thread-safe first, but more important as you will lose it if you try
to get a view of your new object (because in that case, __new__ is not
called).
Instead, try something like that:
def __array_finalize__(self, obj):
self.units = getattr(obj, 'units', yourdefaultunit)
where your defaultunit is the value you would use in __new__. True,
yourdefaultunit may change, and even be lost if there's a break between
__new__ and __array_finalize__, but that should work. Lemme know.
Note that things are always tricky w/ concatenate: when you concatenate your
UnitArray, you should have a UnitArray, OK. But if you mix UnitArray and
ndarray ? What should take precedence ?
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion