{"record":{"id":"e11d465727a1b13c","repo":"pandas-dev/pandas","slug":"cannot-compare-conv-val-of-type-type-conv-val","errorCode":null,"errorMessage":"Cannot compare {conv_val} of type {type(conv_val)} to {kind} column","messagePattern":"Cannot compare (.+?) of type (.+?) to (.+?) column","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/computation/pytables.py","lineNumber":307,"sourceCode":"                conv_val = conv_val.strip().lower() not in [\n                    \"false\",\n                    \"f\",\n                    \"no\",\n                    \"n\",\n                    \"none\",\n                    \"0\",\n                    \"[]\",\n                    \"{}\",\n                    \"\",\n                ]\n            else:\n                conv_val = bool(conv_val)\n            return TermValue(conv_val, conv_val, kind)\n        elif isinstance(conv_val, str):\n            # string quoting\n            return TermValue(conv_val, stringify(conv_val), \"string\")\n        else:\n            raise TypeError(\n                f\"Cannot compare {conv_val} of type {type(conv_val)} to {kind} column\"\n            )\n\n    def convert_values(self) -> None:\n        pass\n\n\nclass FilterBinOp(BinOp):\n    filter: tuple[Any, Any, Index] | None = None\n\n    def __repr__(self) -> str:\n        if self.filter is None:\n            return \"Filter: Not Initialized\"\n        return pprint_thing(f\"[Filter : [{self.filter[0]}] -> [{self.filter[1]}]\")\n\n    def invert(self) -> Self:\n        \"\"\"invert the filter\"\"\"\n        if self.filter is not None:","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/computation/pytables.py#L289-L325","documentation":"Raised in TermValue/convert_value (pytables) when the right-hand-side value of a comparison cannot be coerced to the column's declared kind. The function handles integer, float, bool, and string columns; anything else (lists, dicts, complex, datetime objects that are not handled earlier, custom types) falls through to the else branch and raises TypeError. The message reports both the value and its Python type alongside the target column kind.","triggerScenarios":"store.select('df', where='A == [1,2,3]') (list compared to integer column), store.select('df', where='A == 1+2j') (complex vs integer), or comparing an unsupported object type. Also when a datetime RHS slips past the datetime branch and reaches the generic else.","commonSituations":"Passing a Python list to emulate an 'in' filter (use 'in' operator instead). Comparing a string column to bytes, or an integer column to a Decimal that fails Decimal->int. Mismatched dtypes between the stored data_column and the literal in the where clause.","solutions":["Use the 'in' / 'not in' operators for membership instead of comparing to a list literal: store.select('df', where='A in [1,2,3]').","Convert the RHS literal to the column's dtype before writing the query: store.select('df', where='A == 5') for an integer column.","For complex/Decimal/object comparisons, read the data and filter in pandas.","Verify the data_column dtype with store.get_storer('df').table.coldtypes['A'] and align your literal."],"exampleFix":"// before\nstore.select('df', where='A == [1, 2, 3]')\n\n// after\nstore.select('df', where='A in [1, 2, 3]')\n# or for a single value\nstore.select('df', where='A == 1')","handlingStrategy":"validation","validationCode":"import numpy as np\n\ndef rhs_comparable(value, kind: str) -> bool:\n    if kind in ('integer', 'float'):\n        return isinstance(value, (int, float, np.integer, np.floating)) and not isinstance(value, bool)\n    if kind == 'bool':\n        return isinstance(value, (bool, np.bool_, int, str))\n    if kind == 'string':\n        return isinstance(value, str)\n    return False\n\nkind = store.get_storer('df').table.coldtypes['A'].name\nassert rhs_comparable(literal, kind), f'literal not comparable to {kind} column'","typeGuard":"def is_comparable_scalar(value, kind: str) -> bool:\n    if kind in ('integer', 'float'):\n        return isinstance(value, (int, float)) and not isinstance(value, bool)\n    if kind == 'string':\n        return isinstance(value, str)\n    if kind == 'bool':\n        return isinstance(value, (bool, str))\n    return False","tryCatchPattern":"try:\n    store.select('df', where='A == [1,2,3]')\nexcept TypeError as e:\n    if 'Cannot compare' in str(e):\n        store.select('df', where='A in [1,2,3]')\n    else:\n        raise","preventionTips":["Use 'in'/'not in' for membership rather than comparing to a list literal.","Match the literal's Python type to the column dtype.","Verify coldtypes before constructing where clauses."],"tags":["pandas","hdfstore","pytables","type-mismatch","where","coercion"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}