small suggestion for numpy.testing utils

Hello, I am using numpy's assert_array_equal and assert_array_almost_equal to unit test my physical quantities package. I made a single minor change to assert_array_compare that I think might make these functions more useful to ndarray subclasses, and thought maybe they could be useful to numpy itself. I tried applying this diff to numpy and running the test suite, and instead of 9 known failures I got 1 known failure, 11 skips, 2 errors and 2 failures. Perhaps it is possible that by not forcing the input arrays to be ndarray instances, some additional numpy features are exposed. Thanks, Darren $ svn diff Index: numpy/testing/utils.py =================================================================== --- numpy/testing/utils.py (revision 6370) +++ numpy/testing/utils.py (working copy) @@ -240,9 +240,9 @@ def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header=''): - from numpy.core import asarray, isnan, any - x = asarray(x) - y = asarray(y) + from numpy.core import array, isnan, any + x = array(x, copy=False, subok=True) + y = array(y, copy=False, subok=True) def isnumber(x): return x.dtype.char in '?bhilqpBHILQPfdgFDG'

On Sun, Feb 22, 2009 at 3:17 PM, Darren Dale <dsdale24@gmail.com> wrote:
Hello,
I am using numpy's assert_array_equal and assert_array_almost_equal to unit test my physical quantities package. I made a single minor change to assert_array_compare that I think might make these functions more useful to ndarray subclasses, and thought maybe they could be useful to numpy itself. I tried applying this diff to numpy and running the test suite, and instead of 9 known failures I got 1 known failure, 11 skips, 2 errors and 2 failures. Perhaps it is possible that by not forcing the input arrays to be ndarray instances, some additional numpy features are exposed.
Thanks, Darren
$ svn diff Index: numpy/testing/utils.py =================================================================== --- numpy/testing/utils.py (revision 6370) +++ numpy/testing/utils.py (working copy) @@ -240,9 +240,9 @@
def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header=''): - from numpy.core import asarray, isnan, any - x = asarray(x) - y = asarray(y) + from numpy.core import array, isnan, any + x = array(x, copy=False, subok=True) + y = array(y, copy=False, subok=True)
def isnumber(x): return x.dtype.char in '?bhilqpBHILQPfdgFDG'
Actually, my svn checkout was not up to date. With this patch applied, I get 1 known failure and 11 skips.

On Sun, Feb 22, 2009 at 3:22 PM, Darren Dale <dsdale24@gmail.com> wrote:
On Sun, Feb 22, 2009 at 3:17 PM, Darren Dale <dsdale24@gmail.com> wrote:
Hello,
I am using numpy's assert_array_equal and assert_array_almost_equal to unit test my physical quantities package. I made a single minor change to assert_array_compare that I think might make these functions more useful to ndarray subclasses, and thought maybe they could be useful to numpy itself. I tried applying this diff to numpy and running the test suite, and instead of 9 known failures I got 1 known failure, 11 skips, 2 errors and 2 failures. Perhaps it is possible that by not forcing the input arrays to be ndarray instances, some additional numpy features are exposed.
Thanks, Darren
$ svn diff Index: numpy/testing/utils.py =================================================================== --- numpy/testing/utils.py (revision 6370) +++ numpy/testing/utils.py (working copy) @@ -240,9 +240,9 @@
def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header=''): - from numpy.core import asarray, isnan, any - x = asarray(x) - y = asarray(y) + from numpy.core import array, isnan, any + x = array(x, copy=False, subok=True) + y = array(y, copy=False, subok=True)
def isnumber(x): return x.dtype.char in '?bhilqpBHILQPfdgFDG'
Actually, my svn checkout was not up to date. With this patch applied, I get 1 known failure and 11 skips.
I just double checked and I think I get the same results running the svn 6456 test suite with and without this patch applied. I tried posting an enhancement request at the trac website, but I cant file the ticket because I get "500 Internal Server Error", so I'm posting it here.

Darren, What's the difference between asanyarray(y) and array(y, copy=False, subok=True)? I thought asanyarray would also do what you want. -Andrew Darren Dale wrote:
On Sun, Feb 22, 2009 at 3:22 PM, Darren Dale <dsdale24@gmail.com <mailto:dsdale24@gmail.com>> wrote:
On Sun, Feb 22, 2009 at 3:17 PM, Darren Dale <dsdale24@gmail.com <mailto:dsdale24@gmail.com>> wrote:
Hello,
I am using numpy's assert_array_equal and assert_array_almost_equal to unit test my physical quantities package. I made a single minor change to assert_array_compare that I think might make these functions more useful to ndarray subclasses, and thought maybe they could be useful to numpy itself. I tried applying this diff to numpy and running the test suite, and instead of 9 known failures I got 1 known failure, 11 skips, 2 errors and 2 failures. Perhaps it is possible that by not forcing the input arrays to be ndarray instances, some additional numpy features are exposed.
Thanks, Darren
$ svn diff Index: numpy/testing/utils.py =================================================================== --- numpy/testing/utils.py (revision 6370) +++ numpy/testing/utils.py (working copy) @@ -240,9 +240,9 @@
def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header=''): - from numpy.core import asarray, isnan, any - x = asarray(x) - y = asarray(y) + from numpy.core import array, isnan, any + x = array(x, copy=False, subok=True) + y = array(y, copy=False, subok=True)
def isnumber(x): return x.dtype.char in '?bhilqpBHILQPfdgFDG'
Actually, my svn checkout was not up to date. With this patch applied, I get 1 known failure and 11 skips.
I just double checked and I think I get the same results running the svn 6456 test suite with and without this patch applied. I tried posting an enhancement request at the trac website, but I cant file the ticket because I get "500 Internal Server Error", so I'm posting it here. ------------------------------------------------------------------------
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion

I think they are identical, its just that asanyarray appears to be targeted for exactly this use-case, so perhaps it is a little faster. I just posted that asanyarray would probably have been a better choice, the posts must have crossed. On Sun, Feb 22, 2009 at 6:52 PM, Andrew Straw <strawman@astraw.com> wrote:
Darren,
What's the difference between asanyarray(y) and array(y, copy=False, subok=True)? I thought asanyarray would also do what you want.
-Andrew
Darren Dale wrote:
On Sun, Feb 22, 2009 at 3:22 PM, Darren Dale <dsdale24@gmail.com <mailto:dsdale24@gmail.com>> wrote:
On Sun, Feb 22, 2009 at 3:17 PM, Darren Dale <dsdale24@gmail.com <mailto:dsdale24@gmail.com>> wrote:
Hello,
I am using numpy's assert_array_equal and assert_array_almost_equal to unit test my physical quantities package. I made a single minor change to assert_array_compare that I think might make these functions more useful to ndarray subclasses, and thought maybe they could be useful to numpy itself. I tried applying this diff to numpy and running the test suite, and instead of 9 known failures I got 1 known failure, 11 skips, 2 errors and 2 failures. Perhaps it is possible that by not forcing the input arrays to be ndarray instances, some additional numpy features are exposed.
Thanks, Darren
$ svn diff Index: numpy/testing/utils.py
===================================================================
--- numpy/testing/utils.py (revision 6370) +++ numpy/testing/utils.py (working copy) @@ -240,9 +240,9 @@
def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header=''): - from numpy.core import asarray, isnan, any - x = asarray(x) - y = asarray(y) + from numpy.core import array, isnan, any + x = array(x, copy=False, subok=True) + y = array(y, copy=False, subok=True)
def isnumber(x): return x.dtype.char in '?bhilqpBHILQPfdgFDG'
Actually, my svn checkout was not up to date. With this patch applied, I get 1 known failure and 11 skips.
I just double checked and I think I get the same results running the svn 6456 test suite with and without this patch applied. I tried posting an enhancement request at the trac website, but I cant file the ticket because I get "500 Internal Server Error", so I'm posting it here. ------------------------------------------------------------------------
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion

Hi Darren 2009/2/22 Darren Dale <dsdale24@gmail.com>:
I am using numpy's assert_array_equal and assert_array_almost_equal to unit test my physical quantities package. I made a single minor change to assert_array_compare that I think might make these functions more useful to ndarray subclasses, and thought maybe they could be useful to numpy itself.
Your patch makes good sense. I applied it in r6457. I'll keep an eye on the thread to see if anyone else has further comments. Thanks! Stéfan

On Sun, Feb 22, 2009 at 5:12 PM, Stéfan van der Walt <stefan@sun.ac.za>wrote:
Hi Darren
2009/2/22 Darren Dale <dsdale24@gmail.com>:
I am using numpy's assert_array_equal and assert_array_almost_equal to unit test my physical quantities package. I made a single minor change to assert_array_compare that I think might make these functions more useful to ndarray subclasses, and thought maybe they could be useful to numpy itself.
Your patch makes good sense. I applied it in r6457. I'll keep an eye on the thread to see if anyone else has further comments.
That's great, thank you. I finally got the trac website to take the ticket, by the way. Darren

On Sun, Feb 22, 2009 at 5:39 PM, Stéfan van der Walt <stefan@sun.ac.za>wrote:
2009/2/23 Darren Dale <dsdale24@gmail.com>:
That's great, thank you. I finally got the trac website to take the ticket, by the way.
Actually, it's been taking all your tickets... from 1016 through 1021 :)
Oops, sorry about that. (I was taking a drink of water when I read this and it nearly came out my nose)

On Sun, Feb 22, 2009 at 5:12 PM, Stéfan van der Walt <stefan@sun.ac.za>wrote:
Hi Darren
2009/2/22 Darren Dale <dsdale24@gmail.com>:
I am using numpy's assert_array_equal and assert_array_almost_equal to unit test my physical quantities package. I made a single minor change to assert_array_compare that I think might make these functions more useful to ndarray subclasses, and thought maybe they could be useful to numpy itself.
Your patch makes good sense. I applied it in r6457. I'll keep an eye on the thread to see if anyone else has further comments.
Pierre just drew my attention to asanyarray, I think that would have been a better choice for my patch.

2009/2/23 Darren Dale <dsdale24@gmail.com>:
On Sun, Feb 22, 2009 at 5:12 PM, Stéfan van der Walt <stefan@sun.ac.za> wrote:
Hi Darren
2009/2/22 Darren Dale <dsdale24@gmail.com>:
I am using numpy's assert_array_equal and assert_array_almost_equal to unit test my physical quantities package. I made a single minor change to assert_array_compare that I think might make these functions more useful to ndarray subclasses, and thought maybe they could be useful to numpy itself.
Your patch makes good sense. I applied it in r6457. I'll keep an eye on the thread to see if anyone else has further comments.
Pierre just drew my attention to asanyarray, I think that would have been a better choice for my patch.
Asanyarray is just return array(a, dtype, copy=False, order=order, subok=True) with default values for dtype=None and order=None. I think your original suggestion more clearly shows what the function is meant to achieve. Cheers Stéfan
participants (3)
-
Andrew Straw
-
Darren Dale
-
Stéfan van der Walt