8000 Merge pull request #7152 from bertrand-l/fix/unicode-kwarg-breaks-pad · numpy/numpy@3bc8ed4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3bc8ed4

Browse files
committed
Merge pull request #7152 from bertrand-l/fix/unicode-kwarg-breaks-pad
BUG: mode kwargs passed as unicode to np.pad raises an exception
2 parents d077cf5 + 32ae04a commit 3bc8ed4

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

numpy/lib/arraypad.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,7 @@ def pad(array, pad_width, mode, **kwargs):
13371337
'reflect_type': 'even',
13381338
}
13391339

1340-
if isinstance(mode, str):
1340+
if isinstance(mode, np.compat.basestring):
13411341
# Make sure have allowed kwargs appropriate for mode
13421342
for key in kwargs:
13431343
if key not in allowedkwargs[mode]:

numpy/lib/tests/test_arraypad.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,17 @@ def test_check_simple(self):
953953
assert_array_equal(a, b)
954954

955955

956+
class TestUnicodeInput(TestCase):
957+
def test_unicode_mode(< 7C65 span class=pl-s1>self):
958+
try:
959+
constant_mode = unicode('constant')
960+
except NameError:
961+
constant_mode = 'constant'
962+
a = np.pad([1], 2, mode=constant_mode)
963+
b = np.array([0, 0, 1, 0, 0])
964+
assert_array_equal(a, b)
965+
966+
956967
class ValueError1(TestCase):
957968
def test_check_simple(self):
958969
arr = np.arange(30)

0 commit comments

Comments
 (0)
0