Traits: Array versus Array(Float)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Traits: Array versus Array(Float)

Brad Buran
As shown by the following code snippet, Numpy's isnan does not work with Array traits that have a subtype specified (e.g. Array(Float)).  Is this expected behavior?  I found this bug because Chaco uses isnan in places (e.g. LinePlot).  It's easy for me to work around this, but thought I'd point it out if you're interested in investigating this.

Thanks,
Brad

from enthought.traits.api import HasTraits, Array, Float
from numpy import arange, isnan

class Signal(HasTraits):

    signal = Array
    signal_strict = Array(Float)

    def _signal_default(self):
        return arange(10)

    def _signal_strict_default(self):
        return arange(10)

if __name__ == '__main__':
    signal = Signal()
    print type(signal.signal)
    print isnan(signal.signal)
    print type(signal.signal_strict)
    print isnan(signal.signal_strict)

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Traits: Array versus Array(Float)

Robert Kern
On Tue, Jan 12, 2010 at 17:12, Brad Buran <[hidden email]> wrote:
> As shown by the following code snippet, Numpy's isnan does not work with
> Array traits that have a subtype specified (e.g. Array(Float)).  Is this
> expected behavior?

The Array constructor expects a numpy dtype there or something that it
can interpret as a dtype (like the builtin float type). Do not use
trait types there.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev