Skip to content

Commit 558a585

Browse files
committed
BUG: fix case of a category value which isn't exists (pandas-dev#39189)
1 parent ce3e57b commit 558a585

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

pandas/core/computation/pytables.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,10 @@ def stringify(value):
210210
return TermValue(int(v), v, kind)
211211
elif meta == "category":
212212
metadata = extract_array(self.metadata, extract_numpy=True)
213-
result = metadata.searchsorted(v, side="left")
214-
215-
# result returns 0 if v is first element or if v is not in metadata
216-
# check that metadata contains v
217-
if not result and v not in metadata:
213+
if v not in metadata:
218214
result = -1
215+
else:
216+
result = metadata.searchsorted(v, side="left")
219217
return TermValue(result, result, "integer")
220218
elif kind == "integer":
221219
v = int(float(v))

0 commit comments

Comments
 (0)