Skip to content

Commit 177eceb

Browse files
committed
Optimize cases where trim_zero isn't given an object array
1 parent 2cd23b7 commit 177eceb

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

numpy/lib/_function_base_impl.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1891,7 +1891,13 @@ def _arg_trim_zeros(filt):
18911891
>>> _arg_trim_zeros(np.array([0, 0, 1, 1, 0]))
18921892
(array([2]), array([3]))
18931893
"""
1894-
nonzero = np.argwhere(filt != 0)
1894+
nonzero = (
1895+
np.argwhere(filt)
1896+
if filt.dtype != np.object_
1897+
# Historically, `trim_zeros` treats `None` in an object array
1898+
# as non-zero while argwhere doesn't, account for that
1899+
else np.argwhere(filt != 0)
1900+
)
18951901
if nonzero.size == 0:
18961902
start = stop = np.array([], dtype=np.intp)
18971903
else:

0 commit comments

Comments
 (0)