[NumPy-Tickets] [NumPy] #1433: numpy array captures 'in' statement when it shouldn't

NumPy Trac numpy-tickets@scipy....
Sun Sep 5 15:06:31 CDT 2010


#1433: numpy array captures 'in' statement when it shouldn't
--------------------------+-------------------------------------------------
  Reporter:  graik        |       Owner:  somebody    
      Type:  enhancement  |      Status:  reopened    
  Priority:  normal       |   Milestone:              
 Component:  numpy.core   |     Version:  1.3.0       
Resolution:               |    Keywords:  __contains__
--------------------------+-------------------------------------------------
Changes (by graik):

  * status:  closed => reopened
  * type:  defect => enhancement
  * resolution:  wontfix =>


Comment:

 Thanks for having a look at this. Though I am afraid I disagree. Now I
 haven't checked every version of numpy or Numeric. But we have used this
 construction in a large python library since many years
 (http://biskit.sf.net). First with Numeric then with numpy. It could well
 be that the later Numeric versions were already broken / modified -- we
 kept using some version 23.x because everything later became increasingly
 unstable. I also made a big leap in numpy versions from a very early to
 the latest one.

 Anyway, this is non-python behavior. It seems then that numpy's equality
 operation should be fixed. Python data types have an expected behavior --
 if compared to some other (incompatible) data type, they simply return
 False. This allows many common and elegant short cuts. For example,
 another very frequent pattern in our library was this (assigning a default
 value if None is given):

 {{{
   a = None
   b = a or zeros( 10 )
 }}}

 instead of:
 {{{
   a = None
   b = zeros( 10 )
   if a is not None:
       b = a
 }}}

 It works perfectly fine with all python data types. But because of numpy's
 new __equal__, we had to remove all these constructs. This new ValueError
 is quite annoying. It should only be raised if we are actually comparing
 arrays.

 Greetings,
 Raik

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/1433#comment:2>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list