@@ -205,7 +205,7 @@ def generate(self, v) -> str:
205205 val = v .tostring (self .encoding )
206206 return f"({ self .lhs } { self .op } { val } )"
207207
208- def convert_value (self , v ) -> TermValue :
208+ def convert_value (self , conv_val ) -> TermValue :
209209 """
210210 convert the expression that is in the term to something that is
211211 accepted by pytables
@@ -219,44 +219,44 @@ def stringify(value):
219219 kind = ensure_decoded (self .kind )
220220 meta = ensure_decoded (self .meta )
221221 if kind == "datetime" or (kind and kind .startswith ("datetime64" )):
222- if isinstance (v , (int , float )):
223- v = stringify (v )
224- v = ensure_decoded (v )
225- v = Timestamp (v ).as_unit ("ns" )
226- if v .tz is not None :
227- v = v .tz_convert ("UTC" )
228- return TermValue (v , v ._value , kind )
222+ if isinstance (conv_val , (int , float )):
223+ conv_val = stringify (conv_val )
224+ conv_val = ensure_decoded (conv_val )
225+ conv_val = Timestamp (conv_val ).as_unit ("ns" )
226+ if conv_val .tz is not None :
227+ conv_val = conv_val .tz_convert ("UTC" )
228+ return TermValue (conv_val , conv_val ._value , kind )
229229 elif kind in ("timedelta64" , "timedelta" ):
230- if isinstance (v , str ):
231- v = Timedelta (v )
230+ if isinstance (conv_val , str ):
231+ conv_val = Timedelta (conv_val )
232232 else :
233- v = Timedelta (v , unit = "s" )
234- v = v .as_unit ("ns" )._value
235- return TermValue (int (v ), v , kind )
233+ conv_val = Timedelta (conv_val , unit = "s" )
234+ conv_val = conv_val .as_unit ("ns" )._value
235+ return TermValue (int (conv_val ), conv_val , kind )
236236 elif meta == "category" :
237237 metadata = extract_array (self .metadata , extract_numpy = True )
238238 result : npt .NDArray [np .intp ] | np .intp | int
239- if v not in metadata :
239+ if conv_val not in metadata :
240240 result = - 1
241241 else :
242- result = metadata .searchsorted (v , side = "left" )
242+ result = metadata .searchsorted (conv_val , side = "left" )
243243 return TermValue (result , result , "integer" )
244244 elif kind == "integer" :
245245 try :
246- v_dec = Decimal (v )
246+ v_dec = Decimal (conv_val )
247247 except InvalidOperation :
248248 # GH 54186
249249 # convert v to float to raise float's ValueError
250- float (v )
250+ float (conv_val )
251251 else :
252- v = int (v_dec .to_integral_exact (rounding = "ROUND_HALF_EVEN" ))
253- return TermValue (v , v , kind )
252+ conv_val = int (v_dec .to_integral_exact (rounding = "ROUND_HALF_EVEN" ))
253+ return TermValue (conv_val , conv_val , kind )
254254 elif kind == "float" :
255- v = float (v )
256- return TermValue (v , v , kind )
255+ conv_val = float (conv_val )
256+ return TermValue (conv_val , conv_val , kind )
257257 elif kind == "bool" :
258- if isinstance (v , str ):
259- v = v .strip ().lower () not in [
258+ if isinstance (conv_val , str ):
259+ conv_val = conv_val .strip ().lower () not in [
260260 "false" ,
261261 "f" ,
262262 "no" ,
@@ -268,13 +268,13 @@ def stringify(value):
268268 "" ,
269269 ]
270270 else :
271- v = bool (v )
272- return TermValue (v , v , kind )
273- elif isinstance (v , str ):
271+ conv_val = bool (conv_val )
272+ return TermValue (conv_val , conv_val , kind )
273+ elif isinstance (conv_val , str ):
274274 # string quoting
275- return TermValue (v , stringify (v ), "string" )
275+ return TermValue (conv_val , stringify (conv_val ), "string" )
276276 else :
277- raise TypeError (f"Cannot compare { v } of type { type (v )} to { kind } column" )
277+ raise TypeError (f"Cannot compare { conv_val } of type { type (conv_val )} to { kind } column" )
278278
279279 def convert_values (self ) -> None :
280280 pass
0 commit comments