summaryrefslogtreecommitdiff
path: root/numpy/lib/arraypad.py
diff options
context:
space:
mode:
authorLars G <lagru@mailbox.org>2018-05-02 12:54:08 +0200
committerLars G <lagru@mailbox.org>2018-05-02 13:03:43 +0200
commit51ef0c409e20490829218c4d549a3bd4c9b073a2 (patch)
tree6f40557b763f2686cab48984bf7f50469e86273f /numpy/lib/arraypad.py
parent820765d762513510a8e46f108e8bc8b366127f8f (diff)
downloadnumpy-51ef0c409e20490829218c4d549a3bd4c9b073a2.tar.gz
BUG: Fix padding with large integers
The old way of creating the padded array padded with wrong values for large integers because the new prepended / appended array was implicitly created with dtype float64: >>> (np.zeros(1) + (2 ** 64 - 1)).astype(np.uint64) array([0], np.uint64) >>> (np.zeros(1) + (2 ** 63 - 1)).astype(np.int64) array([-9223372036854775808])
Diffstat (limited to 'numpy/lib/arraypad.py')
-rw-r--r--numpy/lib/arraypad.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/numpy/lib/arraypad.py b/numpy/lib/arraypad.py
index daaa68d06..9f33753b7 100644
--- a/numpy/lib/arraypad.py
+++ b/numpy/lib/arraypad.py
@@ -104,8 +104,8 @@ def _prepend_const(arr, pad_amt, val, axis=-1):
return np.concatenate((np.zeros(padshape, dtype=arr.dtype), arr),
axis=axis)
else:
- return np.concatenate(((np.zeros(padshape) + val).astype(arr.dtype),
- arr), axis=axis)
+ return np.concatenate((np.full(padshape, val, dtype=arr.dtype), arr),
+ axis=axis)
def _append_const(arr, pad_amt, val, axis=-1):
@@ -138,8 +138,8 @@ def _append_const(arr, pad_amt, val, axis=-1):
return np.concatenate((arr, np.zeros(padshape, dtype=arr.dtype)),
axis=axis)
else:
- return np.concatenate(
- (arr, (np.zeros(padshape) + val).astype(arr.dtype)), axis=axis)
+ return np.concatenate((arr, np.full(padshape, val, dtype=arr.dtype)),
+ axis=axis)
def _prepend_edge(arr, pad_amt, axis=-1):