diff options
author | gfyoung <gfyoung@mit.edu> | 2016-01-13 13:15:21 +0000 |
---|---|---|
committer | gfyoung <gfyoung@mit.edu> | 2016-03-15 15:04:05 +0100 |
commit | 9128ed5198cc8544406467a00824e5fe6791f090 (patch) | |
tree | ca3dc831ff1566a2794e940d1a358a17774fd59b /numpy/lib | |
parent | e034b86d1f40af6e15a829d093232febd4a708c3 (diff) | |
download | numpy-9128ed5198cc8544406467a00824e5fe6791f090.tar.gz |
BUG: Fix string copying for np.place
Fixes bug in string copying in np.place
in which replacements strings that were
smaller than their replaced elements
would only partially replace the element
instead of the entire element.
Closes gh-6974.
Addendum: this commit also appears to have
fixed issue with overflow for very large
input arrays.
Closes gh-7207.
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/function_base.py | 3 | ||||
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 5 |
2 files changed, 7 insertions, 1 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index c155babef..648eb5019 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -2026,7 +2026,8 @@ def place(arr, mask, vals): vals : 1-D sequence Values to put into `a`. Only the first N elements are used, where N is the number of True values in `mask`. If `vals` is smaller - than N it will be repeated. + than N, it will be repeated, and if elements of `a` are to be masked, + this sequence must be non-empty. See Also -------- diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index e04a497c1..945992fc0 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -805,6 +805,11 @@ class TestExtins(TestCase): assert_raises_regex(ValueError, "Cannot insert from an empty array", lambda: place(a, [0, 0, 0, 0, 0, 1, 0], [])) + # See Issue #6974 + a = np.array(['12', '34']) + place(a, [0, 1], '9') + assert_array_equal(a, ['12', '9']) + def test_both(self): a = rand(10) mask = a > 0.5 |