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( 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):