From b0d6d236cf0fc48caad7336deca3b2998f5866a8 Mon Sep 17 00:00:00 2001 From: Lars Buitinck Date: Tue, 19 Jul 2011 11:16:29 +0200 Subject: [PATCH 1/2] BUG: fix asarray_chkfinite to take dtype and order args, as advertised Includes a doctest for dtype. --- numpy/lib/function_base.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 3372f8aea177..d20304a1b25b 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -524,7 +524,7 @@ def average(a, axis=None, weights=None, returned=False): else: return avg -def asarray_chkfinite(a): +def asarray_chkfinite(a, dtype=None, order=None): """ Convert the input to an array, checking for NaNs or Infs. @@ -570,8 +570,8 @@ class ndarray is returned. ``asarray_chkfinite`` is identical to ``asarray``. >>> a = [1, 2] - >>> np.asarray_chkfinite(a) - array([1, 2]) + >>> np.asarray_chkfinite(a, dtype=float) + array([1., 2.]) Raises ValueError if array_like contains Nans or Infs. @@ -584,7 +584,7 @@ class ndarray is returned. ValueError """ - a = asarray(a) + a = asarray(a, dtype=dtype, order=order) if (a.dtype.char in typecodes['AllFloat']) \ and (_nx.isnan(a).any() or _nx.isinf(a).any()): raise ValueError( From 48fdc0042460ff29c677c9e517ec62364db25827 Mon Sep 17 00:00:00 2001 From: Lars Buitinck Date: Tue, 19 Jul 2011 15:40:33 +0200 Subject: [PATCH 2/2] Regression test for missing dtype and order args in asarray_chkfinite --- numpy/lib/tests/test_function_base.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index e65c84158101..9df1a916f276 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -793,6 +793,12 @@ def test_simple(self): assert_raises(ValueError, numpy.lib.asarray_chkfinite, b) assert_raises(ValueError, numpy.lib.asarray_chkfinite, c) + def test_dtype_order(self): + """Regression test for missing dtype and order arguments""" + a = [1, 2, 3] + a = numpy.lib.asarray_chkfinite(a, order='F', dtype=numpy.float64) + assert_(a.dtype == numpy.float64) + class TestNaNFuncts(TestCase): def setUp(self):