@@ -205,7 +205,7 @@ def generate(self, v) -> str:
205
205
val = v .tostring (self .encoding )
206
206
return f"({ self .lhs } { self .op } { val } )"
207
207
208
- def convert_value (self , v ) -> TermValue :
208
+ def convert_value (self , conv_val ) -> TermValue :
209
209
"""
210
210
convert the expression that is in the term to something that is
211
211
accepted by pytables
@@ -219,44 +219,44 @@ def stringify(value):
219
219
kind = ensure_decoded (self .kind )
220
220
meta = ensure_decoded (self .meta )
221
221
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 )
229
229
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 )
232
232
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 )
236
236
elif meta == "category" :
237
237
metadata = extract_array (self .metadata , extract_numpy = True )
238
238
result : npt .NDArray [np .intp ] | np .intp | int
239
- if v not in metadata :
239
+ if conv_val not in metadata :
240
240
result = - 1
241
241
else :
242
- result = metadata .searchsorted (v , side = "left" )
242
+ result = metadata .searchsorted (conv_val , side = "left" )
243
243
return TermValue (result , result , "integer" )
244
244
elif kind == "integer" :
245
245
try :
246
- v_dec = Decimal (v )
246
+ v_dec = Decimal (conv_val )
247
247
except InvalidOperation :
248
248
# GH 54186
249
249
# convert v to float to raise float's ValueError
250
- float (v )
250
+ float (conv_val )
251
251
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 )
254
254
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 )
257
257
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 [
260
260
"false" ,
261
261
"f" ,
262
262
"no" ,
@@ -268,13 +268,13 @@ def stringify(value):
268
268
"" ,
269
269
]
270
270
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 ):
274
274
# string quoting
275
- return TermValue (v , stringify (v ), "string" )
275
+ return TermValue (conv_val , stringify (conv_val ), "string" )
276
276
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" )
278
278
279
279
def convert_values (self ) -> None :
280
280
pass
0 commit comments