@@ -2056,24 +2056,19 @@ def _isnonzero_vec(v):
20562056_isnonzero_vec = np .vectorize (_isnonzero_vec , otypes = [bool ])
20572057
20582058
2059+ def _isnonzero (a ):
2060+ # Output of np.vectorize can't be pickled
2061+ return _isnonzero_vec (a )
2062+
2063+
20592064def isnonzero (a ):
2060- if a .dtype .kind in {"U" , "S" }:
2061- # NumPy treats all-whitespace strings as falsy (like in `np.nonzero`).
2062- # but not in `.astype(bool)`. To match the behavior of numpy at least until
2063- # 1.19, we use `_isnonzero_vec`. When NumPy changes behavior, we should just
2064- # use the try block below.
2065- # https://github.com/numpy/numpy/issues/9875
2066- return a .map_blocks (_isnonzero_vec , dtype = bool )
2065+ """Handle special cases where conversion to bool does not work correctly.
2066+ xref: https://github.com/numpy/numpy/issues/9479
2067+ """
20672068 try :
2068- np .zeros (tuple () , dtype = a .dtype ).astype (bool )
2069+ np .zeros ([] , dtype = a .dtype ).astype (bool )
20692070 except ValueError :
2070- ######################################################
2071- # Handle special cases where conversion to bool does #
2072- # not work correctly. #
2073- # #
2074- # xref: https://github.com/numpy/numpy/issues/9479 #
2075- ######################################################
2076- return a .map_blocks (_isnonzero_vec , dtype = bool )
2071+ return a .map_blocks (_isnonzero , dtype = bool )
20772072 else :
20782073 return a .astype (bool )
20792074
0 commit comments