[NumPy-Tickets] [NumPy] #1543: assert_almost_equal has bad behavior (decimals=)

NumPy Trac numpy-tickets@scipy....
Wed Jul 14 04:03:16 CDT 2010


#1543: assert_almost_equal has bad behavior (decimals=)
-----------------------------------------+----------------------------------
 Reporter:  pv                           |       Owner:  somebody
     Type:  defect                       |      Status:  new     
 Priority:  normal                       |   Milestone:  1.5.0   
Component:  numpy.testing                |     Version:  devel   
 Keywords:  testing assert almost equal  |  
-----------------------------------------+----------------------------------
 The `decimals=` absolute-tolerance-only approach used in
 `assert_almost_equal` seems wrong in comparing floating point numbers.
 (Not to mention that specifying tolerance by the number of decimals is a
 bit clunky.)

 People may look at the name of the function, and be surprised by things
 like this:
 {{{
 >>> x = 1e99
 >>> y = np.nextafter(x, 1)  # x and y are neighbouring fp numbers!
 >>> np.testing.assert_almost_equal(x, y)
 Traceback (most recent call last):
 ...
 Items are not equal:
 ...
 >>> x = 1e-19
 >>> y = 1e-99
 >>> np.testing.assert_almost_equal(x, y) # passes
 }}}

 The best choice, IMHO, would be to

   - deprecate the `assert_almost_equal` function
   - we already have an ULP comparison function
   - copy the `assert_tol_equal` from `scipy.special` to numpy

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/1543>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list