Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated v to conv_val in that function #60518

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions pandas/core/computation/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def generate(self, v) -> str:
val = v.tostring(self.encoding)
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
accepted by pytables
Expand All @@ -219,44 +219,44 @@ def stringify(value):
kind = ensure_decoded(self.kind)
meta = ensure_decoded(self.meta)
if kind == "datetime" or (kind and kind.startswith("datetime64")):
if isinstance(v, (int, float)):
v = stringify(v)
v = ensure_decoded(v)
v = Timestamp(v).as_unit("ns")
if v.tz is not None:
v = v.tz_convert("UTC")
return TermValue(v, v._value, kind)
if isinstance(conv_val, (int, float)):
conv_val = stringify(conv_val)
conv_val = ensure_decoded(conv_val)
conv_val = Timestamp(conv_val).as_unit("ns")
if conv_val.tz is not None:
conv_val = conv_val.tz_convert("UTC")
return TermValue(conv_val, conv_val._value, kind)
elif kind in ("timedelta64", "timedelta"):
if isinstance(v, str):
v = Timedelta(v)
if isinstance(conv_val, str):
conv_val = Timedelta(conv_val)
else:
v = Timedelta(v, unit="s")
v = v.as_unit("ns")._value
return TermValue(int(v), v, kind)
conv_val = Timedelta(conv_val, unit="s")
conv_val = conv_val.as_unit("ns")._value
return TermValue(int(conv_val), conv_val, kind)
elif meta == "category":
metadata = extract_array(self.metadata, extract_numpy=True)
result: npt.NDArray[np.intp] | np.intp | int
if v not in metadata:
if conv_val not in metadata:
result = -1
else:
result = metadata.searchsorted(v, side="left")
result = metadata.searchsorted(conv_val, side="left")
return TermValue(result, result, "integer")
elif kind == "integer":
try:
v_dec = Decimal(v)
v_dec = Decimal(conv_val)
except InvalidOperation:
# GH 54186
# convert v to float to raise float's ValueError
float(v)
float(conv_val)
else:
v = int(v_dec.to_integral_exact(rounding="ROUND_HALF_EVEN"))
return TermValue(v, v, kind)
conv_val = int(v_dec.to_integral_exact(rounding="ROUND_HALF_EVEN"))
return TermValue(conv_val, conv_val, kind)
elif kind == "float":
v = float(v)
return TermValue(v, v, kind)
conv_val = float(conv_val)
return TermValue(conv_val, conv_val, kind)
elif kind == "bool":
if isinstance(v, str):
v = v.strip().lower() not in [
if isinstance(conv_val, str):
conv_val = conv_val.strip().lower() not in [
"false",
"f",
"no",
Expand All @@ -268,13 +268,13 @@ def stringify(value):
"",
]
else:
v = bool(v)
return TermValue(v, v, kind)
elif isinstance(v, str):
conv_val = bool(conv_val)
return TermValue(conv_val, conv_val, kind)
elif isinstance(conv_val, str):
# string quoting
return TermValue(v, stringify(v), "string")
return TermValue(conv_val, stringify(conv_val), "string")
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:
pass
Expand Down
Loading