55"""
66
77import re
8+ from contextlib import suppress
89
910import numpy
1011import pyarrow
@@ -147,7 +148,7 @@ def _inner_filter_operations(arr, operator, value):
147148 """
148149 if not operator .startswith (("AnyOp" , "AllOp" )) and len (value ) == 1 :
149150 value = value [0 ]
150- if hasattr ( value , "item" ):
151+ with suppress ( AttributeError ):
151152 value = value .item ()
152153 if isinstance (value , (tuple , list )):
153154 value = pyarrow .array (value )
@@ -165,24 +166,24 @@ def _inner_filter_operations(arr, operator, value):
165166 if operator == "GtEq" :
166167 return compute .greater_equal (arr , value ).to_numpy (False ).astype (dtype = bool )
167168 if operator == "InList" :
168- if hasattr ( value , "to_pylist" ):
169+ with suppress ( AttributeError ):
169170 value = value .to_pylist ()
170- if hasattr ( value , "to_numpy" ):
171+ with suppress ( AttributeError ):
171172 value = value .to_numpy (zero_copy_only = False )
172173 values = set (value )
173- if hasattr ( arr , "to_numpy" ):
174+ with suppress ( AttributeError ):
174175 arr = arr .to_numpy (zero_copy_only = False )
175176 if arr .dtype == numpy .int64 :
176177 return list_ops .list_in_list .list_in_list_int64 (memoryview (arr ), values , len (arr ))
177178 else :
178179 return list_ops .list_in_list .list_in_list (arr .astype (object ), values )
179180 if operator == "NotInList" :
180- if hasattr ( value , "to_pylist" ):
181+ with suppress ( AttributeError ):
181182 value = value .to_pylist ()
182- if hasattr ( value , "to_numpy" ):
183+ with suppress ( AttributeError ):
183184 value = value .to_numpy (zero_copy_only = False )
184185 values = set (value )
185- if hasattr ( arr , "to_numpy" ):
186+ with suppress ( AttributeError ):
186187 arr = arr .to_numpy (zero_copy_only = False )
187188 if arr .dtype == numpy .int64 :
188189 matches = list_ops .list_in_list .list_in_list_int64 (memoryview (arr ), values , len (arr ))
0 commit comments