diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2017-08-06 08:53:09 -0500 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2017-08-06 12:02:04 -0500 |
commit | 917700c8576231004fe541d5956da8ca9188ca7e (patch) | |
tree | c6c1a4c128e68752ef7fa3b0f20b58c98697b678 /numpy | |
parent | 2489aded2dc7f779a66b5f93ea59ba4731c46b86 (diff) | |
download | numpy-917700c8576231004fe541d5956da8ca9188ca7e.tar.gz |
BUG: Don't allow an array to be passed as the dtype argument
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/lib/tests/test_type_check.py | 8 | ||||
-rw-r--r-- | numpy/lib/type_check.py | 3 |
2 files changed, 8 insertions, 3 deletions
diff --git a/numpy/lib/tests/test_type_check.py b/numpy/lib/tests/test_type_check.py index d863e5924..1b1af86da 100644 --- a/numpy/lib/tests/test_type_check.py +++ b/numpy/lib/tests/test_type_check.py @@ -3,7 +3,7 @@ from __future__ import division, absolute_import, print_function import numpy as np from numpy.compat import long from numpy.testing import ( - assert_, assert_equal, assert_array_equal, run_module_suite + assert_, assert_equal, assert_array_equal, run_module_suite, assert_raises ) from numpy.lib.type_check import ( common_type, mintypecode, isreal, iscomplex, isposinf, isneginf, @@ -422,5 +422,11 @@ class TestArrayConversion(object): assert_equal(a.__class__, np.ndarray) assert_(np.issubdtype(a.dtype, float)) + # previously this would infer dtypes from arrays, unlike every single + # other numpy function + assert_raises(TypeError, + asfarray, np.array([1, 2, 3]), dtype=np.array(1.0)) + + if __name__ == "__main__": run_module_suite() diff --git a/numpy/lib/type_check.py b/numpy/lib/type_check.py index b2de153d3..e6aae8ddd 100644 --- a/numpy/lib/type_check.py +++ b/numpy/lib/type_check.py @@ -98,8 +98,7 @@ def asfarray(a, dtype=_nx.float_): array([ 2., 3.]) """ - dtype = _nx.obj2sctype(dtype) - if not issubclass(dtype, _nx.inexact): + if not _nx.issubdtype(dtype, _nx.inexact): dtype = _nx.float_ return asarray(a, dtype=dtype) |