Skip to content

Fix asarray_chkfinite to take dtype and order arguments, as advertised #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions numpy/lib/function_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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.

Expand All @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions numpy/lib/tests/test_function_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down