From e62d5d15f3b8df247dcb133eaaceb71f5f60d8c0 Mon Sep 17 00:00:00 2001 From: Bas van Beek Date: Tue, 11 Aug 2020 16:17:50 +0200 Subject: MAINT: Catching warnings is expensive; remove it --- numpy/lib/function_base.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'numpy/lib/function_base.py') diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 96e1c6de9..e9fe936e9 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -1644,12 +1644,13 @@ def trim_zeros(filt, trim='fb'): def _trim_zeros_new(filt, trim='fb'): """Newer optimized implementation of ``trim_zeros()``.""" arr_any = np.asanyarray(filt) - with warnings.catch_warnings(): - # not all dtypes support elementwise comparisons with `0` (e.g. str) - warnings.simplefilter('error', FutureWarning) - arr = arr_any != 0 if arr_any.dtype != bool else arr_any + arr = arr_any != 0 if arr_any.dtype != bool else arr_any - if arr.ndim != 1: + if arr is False: + # not all dtypes support elementwise comparisons with `0` (e.g. str); + # they will return `False` instead + raise TypeError('elementwise comparison failed; unsupported data type') + elif arr.ndim != 1: raise ValueError('trim_zeros requires an array of exactly one dimension') elif not len(arr): return filt -- cgit v1.2.1