Skip to content

ENH: Make the mode parameter of np.pad default to 'constant' #4808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions numpy/lib/arraypad.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,12 +957,12 @@ def _as_pairs(x, ndim, as_index=False):
# Public functions


def _pad_dispatcher(array, pad_width, mode, **kwargs):
def _pad_dispatcher(array, pad_width, mode=None, **kwargs):
return (array,)


@array_function_dispatch(_pad_dispatcher, module='numpy')
def pad(array, pad_width, mode, **kwargs):
def pad(array, pad_width, mode='constant', **kwargs):
"""
Pads an array.

Expand All @@ -977,10 +977,10 @@ def pad(array, pad_width, mode, **kwargs):
((before, after),) yields same before and after pad for each axis.
(pad,) or int is a shortcut for before = after = pad width for all
axes.
mode : str or function
mode : str or function, optional
One of the following string values or a user supplied function.

'constant'
'constant' (default)
Pads with a constant value.
'edge'
Pads with the edge values of array.
Expand Down
7 changes: 3 additions & 4 deletions numpy/lib/tests/test_arraypad.py
Original file line number Diff line number Diff line change
Expand Up @@ -1249,10 +1249,9 @@ def test_kwargs(mode):
np.pad([1, 2, 3], 1, mode, **{key: value})


def test_missing_mode():
match = "missing 1 required positional argument: 'mode'"
with pytest.raises(TypeError, match=match):
np.pad(np.ones((5, 6)), 4)
def test_constant_zero_default():
arr = np.array([1, 1])
assert_array_equal(np.pad(arr, 2), [0, 0, 1, 1, 0, 0])


@pytest.mark.parametrize("mode", _all_modes.keys())
Expand Down