[Numpy-discussion] comparing string array with None raises ValueError

Sebastian Haase haase at msg.ucsf.edu
Thu Jun 24 13:39:06 CDT 2004


On Thursday 24 June 2004 01:10 pm, Todd Miller wrote:
> On Thu, 2004-06-24 at 15:26, David M. Cooke wrote:
> > On June 24, 2004 01:46 pm, Sebastian Haase wrote:
> > > In general it must be OK to compare anything with None, right ?
> > > (BTW, I get the same error with == and !=)
> >
> > No! Not in general!
>
> Well,  this is a good point.  I think the current numerical behavior was
> a hack I stuck in for people who might not be aware of "is".  It's
> looking like a mistake now.
>
> > I learnt this back when Numeric implemented rich
> > comparisions; suddenly, lots of my code broke. You don't actually want
> > "is this object _equal_ (or not equal) to None", you want "is this object
> > None", as None is a singleton.
>
> However,  given the context of the original question, Sebastian's code
>
> doesn't read like *that* kind of None comparison:
> > > > > type '10a80' - that is, an array of 10 80 char 'strings' :
> > > > > >>> q.Mrc.hdr = q.Mrc.hdrArray[0].field
> > > > > >>> q.Mrc.hdr('title') != None
>
> q.Mrc.hdr('title') is pretty clearly a character array, ergo, it's not
> None.  What did you want it to do Sebastian?

q.Mrc.hdr('title') is rather an array of 10 'character array' .. that's 
different, isn't it ?
In any case, I actually already changed my code to the check of 'is None' - 
which is probably what I wanted anyway. 
So, the only argument left, is that the original error/exception message I got 
was kind of "ugly" ;-) And I think/thought if 'something' cannot be 
_converted_ to a string array it can't _be_  '==' a string array. That's just 
why I expected the simple result to be 'False'.
But now I understand that if comparing an array to a scalar (maybe 'None') you 
always have to decide if this actually compares "the whole array" with the 
scalar, or if the comparison get "put through" and done on each element 
"separately" ...
which it seems is already decided at least in the numerical array case.


Regards,
Sebastian




More information about the Numpy-discussion mailing list