Skip to content

Commit aa422b7

Browse files
committed
MAINT: Address attribute error in trim_zeros
1 parent 53ebda1 commit aa422b7

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

numpy/lib/function_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1651,7 +1651,7 @@ def trim_zeros(filt, trim='fb', axis=-1):
16511651
if 'b' not in trim:
16521652
stop = (None,) * ndim
16531653

1654-
if start.size == 1:
1654+
if len(start) == 1:
16551655
# filt is 1D -> don't use multi-dimensional slicing to preserve
16561656
# non-array input types
16571657
sl = slice(start[0], stop[0])

numpy/lib/tests/test_function_base.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,18 @@ def test_allzero(self, ndim):
11461146
res = trim_zeros(a, axis=None)
11471147
assert_array_equal(res, np.zeros((0,) * ndim))
11481148

1149+
def test_trim_arg(self):
1150+
a = np.array([0, 1, 2, 0])
1151+
1152+
res = trim_zeros(a, trim='f')
1153+
assert_array_equal(res, [1, 2, 0])
1154+
1155+
res = trim_zeros(a, trim='b')
1156+
assert_array_equal(res, [0, 1, 2])
1157+
1158+
res = trim_zeros(a, trim='')
1159+
assert_array_equal(res, [0, 1, 2, 0])
1160+
11491161

11501162
class TestExtins(object):
11511163

0 commit comments

Comments
 (0)