[SciPy-dev] Re: Fundamental scipy testing changes

Todd Miller jmiller at stsci.edu
Wed Dec 8 09:33:46 CST 2004

On Wed, 2004-12-08 at 06:53, Pearu Peterson wrote:
> On Tue, 7 Dec 2004, Todd Miller wrote:
> >> Note that assert_equal, assert_almost_equal, assert_approx_equal
> >> were not meant to be used with array arguments (I didn't implement them
> >> but its obvious from reading the code).
> >
> > Thanks for pointing this out...  I noticed the array versions only
> > peripherally and didn't understand the distinction.
> May be we need to review assert_equal, etc so that they will
> handle array inputs similar to assert_array_equal but on Python objects
> they will not use unnecessary scipy_base.all. And then define
> assert_array_equal = assert_equal
> assert_array_almost_equal = assert_almost_equal
> in testing.py for backward compability and declare their use as 
> depreciated.

This sounds like a good interface simplification.  I looked at doing the
deprecation (sticking in warnings) but was quickly intimidated by the
array equality functions.  I think as an alternative to deprecation,  we
should consider having assert_equal delegate to assert_array_equal for
arrays. That way, arrays are handled as they have been,  but future
testers won't have to distinguish between array and non-array contexts. 

> >> For checking the equality of
> >> array arguments assert_array_equal or assert_array_almost_equal should be
> >> used. If some scipy test suite uses assert_equal, etc with array
> >> arguments then I think this is a bug of this particular test suite,
> >> not of testing.py. So, using scipy_base.all in assert_equal, etc is not
> >> necessary (unless we want to drop assert_array_* functions).
> >
> > Understood.  Are we agreed that it is appropriate to use all() in the
> > assert_array_* functions?
> Yes.
> But be careful when replacing `if obj:` with `if all(obj):` in other parts
> of scipy as it may also mean `if any(obj):` or `if obj is not None:`, in 
> fact, I think these are being assumed in most cases. And if not, then 
> it should be a bug.

Sounds good.

> I agree that the usage of `if obj:` is a bug and should be fixed either to
> `if any(obj):` or `if obj is not None:` or rarely `if all(obj):`.

Something else worth explicitly mentioning is array comparisons and
logical expressions,  something like "if A<B:".  For those,  it's
important to say "if all(A<B):" or numarray will raise an exception and
Numeric will really mean "if any(A<B):".  It might also be worth
pointing out that "if A<B and C<D:" should be converted to "if any(A<B)
and any(C<D):" and not "if any(A<B and C<D):".

Thanks again for looking this over.


More information about the Scipy-dev mailing list