[Numpy-discussion] comparing string array with None raises ValueError, more opinions please
jmiller at stsci.edu
Thu Jun 24 12:15:02 CDT 2004
On Thu, 2004-06-24 at 14:53, Rick White wrote:
> On 24 Jun 2004, Todd Miller wrote:
> > OK, I see your point. I talked it over with Perry and he made a
> > reasonable case for allowing comparisons with None (or any object).
> > Perry argued that since None is a common default parameter value, it
> > might simplify code to not have to add logic to handle that case.
> > If no one objects, I'll change numarray.strings so that comparison of a
> > string array with any object not convertible to a string array results
> > in an array of False values.
> > Any objections?
> Hmm, before you do that you might look at this:
> >>> import numarray
> >>> b = numarray.zeros(10)
> >>> b==0
> array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1], type=Bool)
> >>> b==None
> So comparing numeric arrays to None returns a scalar false value since
> the variable b is not None.
Oh yeah... I forgot about that. Numeric comparisons have a special
case for None and blow up for most other arbitrary objects. So there's
>>> a= numarray.arange(100)
>>> a == None
>>> class foo:
>>> a == foo
Traceback (most recent call last):
TypeError: UFunc arguments must be numarray, scalars or numeric
> I figure that the behavior of comparisons to None for string arrays
> numeric arrays ought to be consistent. I don't know which is
So the two choices now on the table are:
1. Change string equality comparisons to return an array of false or
true for objects which don't convert to strings. Change Numeric
equality comparisons in a similar fashion.
2. Special case string equality comparisons for None, as is done with
numerical comparisons. Raise a type error for objects (other than None)
which don't convert to string arrays.
I think I like 2. Other opinions on 1 & 2? Other choices?
More information about the Numpy-discussion