diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2019-08-15 09:24:09 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-15 09:24:09 -0500 |
commit | 0a133311b507151bb7506e9c6313b1d719c894ae (patch) | |
tree | 4f61253fdba06c98396d128becefef1923c9fd39 /numpy/lib/arraypad.py | |
parent | 4b95b70eba7a721f1f4f4b7f7988ba06eda2bf89 (diff) | |
parent | 6f009fce15e7bea11c31c871170a37071761eac4 (diff) | |
download | numpy-0a133311b507151bb7506e9c6313b1d719c894ae.tar.gz |
Merge pull request #14101 from lagru/zero_stat_length
MAINT: Clearer error message while padding with stat_length=0
Diffstat (limited to 'numpy/lib/arraypad.py')
-rw-r--r-- | numpy/lib/arraypad.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/numpy/lib/arraypad.py b/numpy/lib/arraypad.py index f08d425d6..62330e692 100644 --- a/numpy/lib/arraypad.py +++ b/numpy/lib/arraypad.py @@ -323,6 +323,12 @@ def _get_stats(padded, axis, width_pair, length_pair, stat_func): if right_length is None or max_length < right_length: right_length = max_length + if (left_length == 0 or right_length == 0) \ + and stat_func in {np.amax, np.amin}: + # amax and amin can't operate on an emtpy array, + # raise a more descriptive warning here instead of the default one + raise ValueError("stat_length of 0 yields no value for padding") + # Calculate statistic for the left side left_slice = _slice_at_axis( slice(left_index, left_index + left_length), axis) @@ -340,6 +346,7 @@ def _get_stats(padded, axis, width_pair, length_pair, stat_func): right_chunk = padded[right_slice] right_stat = stat_func(right_chunk, axis=axis, keepdims=True) _round_if_needed(right_stat, padded.dtype) + return left_stat, right_stat @@ -835,7 +842,7 @@ def pad(array, pad_width, mode='constant', **kwargs): raise ValueError("unsupported keyword arguments for mode '{}': {}" .format(mode, unsupported_kwargs)) - stat_functions = {"maximum": np.max, "minimum": np.min, + stat_functions = {"maximum": np.amax, "minimum": np.amin, "mean": np.mean, "median": np.median} # Create array with final shape and original values |