Skip to content

Commit 017e47a

Browse files
committed
BUG: change test location (pandas-dev#39189)
1 parent 877ae9e commit 017e47a

File tree

3 files changed

+22
-34
lines changed

3 files changed

+22
-34
lines changed

pandas/core/computation/pytables.py

+6-11
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,12 @@ def stringify(value):
210210
v = Timedelta(v, unit="s").value
211211
return TermValue(int(v), v, kind)
212212
elif meta == "category":
213-
term_value = self._convert_category_value(self.metadata, v)
214-
return term_value
213+
metadata = extract_array(self.metadata, extract_numpy=True)
214+
if v not in metadata:
215+
result = -1
216+
else:
217+
result = metadata.searchsorted(v, side="left")
218+
return TermValue(result, result, "integer")
215219
elif kind == "integer":
216220
v = int(float(v))
217221
return TermValue(v, v, kind)
@@ -240,15 +244,6 @@ def stringify(value):
240244
else:
241245
raise TypeError(f"Cannot compare {v} of type {type(v)} to {kind} column")
242246

243-
@staticmethod
244-
def _convert_category_value(metadata: Series, value: Any) -> TermValue:
245-
metadata = extract_array(metadata, extract_numpy=True)
246-
if value not in metadata:
247-
result = -1
248-
else:
249-
result = metadata.searchsorted(value, side="left")
250-
return TermValue(result, result, "integer")
251-
252247
def convert_values(self):
253248
pass
254249

pandas/tests/computation/test_pytables.py

-23
This file was deleted.

pandas/tests/io/pytables/test_categorical.py

+16
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,19 @@ def test_categorical_nan_only_columns(setup_path):
184184
df.to_hdf(path, "df", format="table", data_columns=True)
185185
result = read_hdf(path, "df")
186186
tm.assert_frame_equal(result, expected)
187+
188+
189+
@pytest.mark.parametrize(
190+
"value, expected_results",
191+
[
192+
('col=="q"', DataFrame({"col": ["a", "b", "s"]}, DataFrame({"col": []}))),
193+
('col=="a"', DataFrame({"col": ["a", "b", "s"]}, DataFrame({"col": ["a"]}))),
194+
],
195+
)
196+
def test_convert_value(setup_path, where: str, df: DataFrame, expected: DataFrame):
197+
# GH39420
198+
# Check that read_hdf with categorical columns can filter by where condition.
199+
with ensure_clean_path(setup_path) as path:
200+
df.to_hdf(path, "df", format="table")
201+
result = read_hdf(path, "df", where=where)
202+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)