From 6ef5ec39cdfaf77aa4600ec2e3bf9f679a4fd527 Mon Sep 17 00:00:00 2001 From: Wansoo Kim Date: Fri, 17 Jul 2020 14:27:44 +0900 Subject: MAINT: Remove Duplicated Code (function extract rmap) (#16847) * MAINT: Remove Duplicated Code (function extract rmap) Co-authored-by: Ross Barnowski --- numpy/lib/arraypad.py | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'numpy/lib/arraypad.py') diff --git a/numpy/lib/arraypad.py b/numpy/lib/arraypad.py index 7569e7651..069e1fab3 100644 --- a/numpy/lib/arraypad.py +++ b/numpy/lib/arraypad.py @@ -207,23 +207,20 @@ def _get_linear_ramps(padded, axis, width_pair, end_value_pair): """ edge_pair = _get_edges(padded, axis, width_pair) - left_ramp = np.linspace( - start=end_value_pair[0], - stop=edge_pair[0].squeeze(axis), # Dimensions is replaced by linspace - num=width_pair[0], - endpoint=False, - dtype=padded.dtype, - axis=axis, - ) - - right_ramp = np.linspace( - start=end_value_pair[1], - stop=edge_pair[1].squeeze(axis), # Dimension is replaced by linspace - num=width_pair[1], - endpoint=False, - dtype=padded.dtype, - axis=axis, + left_ramp, right_ramp = ( + np.linspace( + start=end_value, + stop=edge.squeeze(axis), # Dimension is replaced by linspace + num=width, + endpoint=False, + dtype=padded.dtype, + axis=axis + ) + for end_value, edge, width in zip( + end_value_pair, edge_pair, width_pair + ) ) + # Reverse linear space in appropriate dimension right_ramp = right_ramp[_slice_at_axis(slice(None, None, -1), axis)] -- cgit v1.2.1 From 4690248dd48e11e57167da20e54dc21a5d853bfa Mon Sep 17 00:00:00 2001 From: Noman Arshad Date: Tue, 28 Jul 2020 07:57:34 +0500 Subject: update numpy/lib/arraypad.py with appropriate chain exception (#16953) * update numpy/lib/arraypad.py with appropriate chain exception Co-authored-by: Noman Arshad --- numpy/lib/arraypad.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'numpy/lib/arraypad.py') diff --git a/numpy/lib/arraypad.py b/numpy/lib/arraypad.py index 069e1fab3..8830b8147 100644 --- a/numpy/lib/arraypad.py +++ b/numpy/lib/arraypad.py @@ -780,7 +780,7 @@ def pad(array, pad_width, mode='constant', **kwargs): try: unsupported_kwargs = set(kwargs) - set(allowed_kwargs[mode]) except KeyError: - raise ValueError("mode '{}' is not supported".format(mode)) + raise ValueError("mode '{}' is not supported".format(mode)) from None if unsupported_kwargs: raise ValueError("unsupported keyword arguments for mode '{}': {}" .format(mode, unsupported_kwargs)) -- cgit v1.2.1