diff options
| author | gfyoung <gfyoung@mit.edu> | 2016-01-12 23:16:57 +0000 |
|---|---|---|
| committer | gfyoung <gfyoung@mit.edu> | 2016-01-14 19:05:31 +0000 |
| commit | 02bcbd7e99f7b73c2abcb2726f79ea01a6bba2da (patch) | |
| tree | 1ea2b8bfa8af4b3b99806933de189a83ef48e901 /numpy/lib | |
| parent | 8fa6e3bef26a6d4a2c92f2824129aa4409be2590 (diff) | |
| download | numpy-02bcbd7e99f7b73c2abcb2726f79ea01a6bba2da.tar.gz | |
DOC, MAINT: Enforce np.ndarray arg for np.put and np.place
np.put and np.place do something only when the first argument
is an instance of np.ndarray. These changes will cause a TypeError
to be thrown in either function should that requirement not be
satisfied.
Diffstat (limited to 'numpy/lib')
| -rw-r--r-- | numpy/lib/function_base.py | 6 | ||||
| -rw-r--r-- | numpy/lib/tests/test_function_base.py | 4 | ||||
| -rw-r--r-- | numpy/lib/tests/test_regression.py | 4 |
3 files changed, 9 insertions, 5 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 9bc128f92..844c069c0 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -1779,7 +1779,7 @@ def place(arr, mask, vals): Parameters ---------- - arr : array_like + arr : ndarray Array to put data into. mask : array_like Boolean mask array. Must have the same size as `a`. @@ -1801,6 +1801,10 @@ def place(arr, mask, vals): [44, 55, 44]]) """ + if not isinstance(arr, np.ndarray): + raise TypeError("argument 1 must be numpy.ndarray, " + "not {name}".format(name=type(arr).__name__)) + return _insert(arr, mask, vals) diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index a5ac78e33..88a590517 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -674,6 +674,10 @@ class TestExtins(TestCase): assert_array_equal(b, [3, 2, 2, 3, 3]) def test_place(self): + # Make sure that non-np.ndarray objects + # raise an error instead of doing nothing + assert_raises(TypeError, place, [1, 2, 3], [True, False], [0, 1]) + a = np.array([1, 4, 3, 2, 5, 8, 7]) place(a, [0, 1, 0, 1, 0, 1, 0], [2, 4, 6]) assert_array_equal(a, [1, 2, 3, 4, 5, 6, 7]) diff --git a/numpy/lib/tests/test_regression.py b/numpy/lib/tests/test_regression.py index 00fa3f195..ee50dcfa4 100644 --- a/numpy/lib/tests/test_regression.py +++ b/numpy/lib/tests/test_regression.py @@ -85,10 +85,6 @@ class TestRegression(TestCase): assert_(x != y) assert_(x == x) - def test_mem_insert(self, level=rlevel): - # Ticket #572 - np.lib.place(1, 1, 1) - def test_polyfit_build(self): # Ticket #628 ref = [-1.06123820e-06, 5.70886914e-04, -1.13822012e-01, |
