Skip to content
Snippets Groups Projects
Unverified Commit 59f947ff authored by Michelino Gali's avatar Michelino Gali Committed by GitHub
Browse files

updated v to conv_val in that function (#60518)

parent 07e0bca0
No related branches found
No related tags found
No related merge requests found
...@@ -205,7 +205,7 @@ class BinOp(ops.BinOp): ...@@ -205,7 +205,7 @@ class BinOp(ops.BinOp):
val = v.tostring(self.encoding) val = v.tostring(self.encoding)
return f"({self.lhs} {self.op} {val})" return f"({self.lhs} {self.op} {val})"
def convert_value(self, v) -> TermValue: def convert_value(self, conv_val) -> TermValue:
""" """
convert the expression that is in the term to something that is convert the expression that is in the term to something that is
accepted by pytables accepted by pytables
...@@ -219,44 +219,44 @@ class BinOp(ops.BinOp): ...@@ -219,44 +219,44 @@ class BinOp(ops.BinOp):
kind = ensure_decoded(self.kind) kind = ensure_decoded(self.kind)
meta = ensure_decoded(self.meta) meta = ensure_decoded(self.meta)
if kind == "datetime" or (kind and kind.startswith("datetime64")): if kind == "datetime" or (kind and kind.startswith("datetime64")):
if isinstance(v, (int, float)): if isinstance(conv_val, (int, float)):
v = stringify(v) conv_val = stringify(conv_val)
v = ensure_decoded(v) conv_val = ensure_decoded(conv_val)
v = Timestamp(v).as_unit("ns") conv_val = Timestamp(conv_val).as_unit("ns")
if v.tz is not None: if conv_val.tz is not None:
v = v.tz_convert("UTC") conv_val = conv_val.tz_convert("UTC")
return TermValue(v, v._value, kind) return TermValue(conv_val, conv_val._value, kind)
elif kind in ("timedelta64", "timedelta"): elif kind in ("timedelta64", "timedelta"):
if isinstance(v, str): if isinstance(conv_val, str):
v = Timedelta(v) conv_val = Timedelta(conv_val)
else: else:
v = Timedelta(v, unit="s") conv_val = Timedelta(conv_val, unit="s")
v = v.as_unit("ns")._value conv_val = conv_val.as_unit("ns")._value
return TermValue(int(v), v, kind) return TermValue(int(conv_val), conv_val, kind)
elif meta == "category": elif meta == "category":
metadata = extract_array(self.metadata, extract_numpy=True) metadata = extract_array(self.metadata, extract_numpy=True)
result: npt.NDArray[np.intp] | np.intp | int result: npt.NDArray[np.intp] | np.intp | int
if v not in metadata: if conv_val not in metadata:
result = -1 result = -1
else: else:
result = metadata.searchsorted(v, side="left") result = metadata.searchsorted(conv_val, side="left")
return TermValue(result, result, "integer") return TermValue(result, result, "integer")
elif kind == "integer": elif kind == "integer":
try: try:
v_dec = Decimal(v) v_dec = Decimal(conv_val)
except InvalidOperation: except InvalidOperation:
# GH 54186 # GH 54186
# convert v to float to raise float's ValueError # convert v to float to raise float's ValueError
float(v) float(conv_val)
else: else:
v = int(v_dec.to_integral_exact(rounding="ROUND_HALF_EVEN")) conv_val = int(v_dec.to_integral_exact(rounding="ROUND_HALF_EVEN"))
return TermValue(v, v, kind) return TermValue(conv_val, conv_val, kind)
elif kind == "float": elif kind == "float":
v = float(v) conv_val = float(conv_val)
return TermValue(v, v, kind) return TermValue(conv_val, conv_val, kind)
elif kind == "bool": elif kind == "bool":
if isinstance(v, str): if isinstance(conv_val, str):
v = v.strip().lower() not in [ conv_val = conv_val.strip().lower() not in [
"false", "false",
"f", "f",
"no", "no",
...@@ -268,13 +268,13 @@ class BinOp(ops.BinOp): ...@@ -268,13 +268,13 @@ class BinOp(ops.BinOp):
"", "",
] ]
else: else:
v = bool(v) conv_val = bool(conv_val)
return TermValue(v, v, kind) return TermValue(conv_val, conv_val, kind)
elif isinstance(v, str): elif isinstance(conv_val, str):
# string quoting # string quoting
return TermValue(v, stringify(v), "string") return TermValue(conv_val, stringify(conv_val), "string")
else: else:
raise TypeError(f"Cannot compare {v} of type {type(v)} to {kind} column") raise TypeError(f"Cannot compare {conv_val} of type {type(conv_val)} to {kind} column")
def convert_values(self) -> None: def convert_values(self) -> None:
pass pass
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment