{"record":{"id":"ecb7d85e0a8eb12f","repo":"pandas-dev/pandas","slug":"only-list-like-objects-are-allowed-to-be-passed-to-ecb7d8","errorCode":null,"errorMessage":"only list-like objects are allowed to be passed to isin(), you passed a `{type(values).__name__}`","messagePattern":"only list-like objects are allowed to be passed to isin\\(\\), you passed a `(.+?)`","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/algorithms.py","lineNumber":530,"sourceCode":"    Compute the isin boolean array.\n\n    Parameters\n    ----------\n    comps : list-like\n    values : list-like\n\n    Returns\n    -------\n    ndarray[bool]\n        Same length as `comps`.\n    \"\"\"\n    if not is_list_like(comps):\n        raise TypeError(\n            \"only list-like objects are allowed to be passed \"\n            f\"to isin(), you passed a `{type(comps).__name__}`\"\n        )\n    if not is_list_like(values):\n        raise TypeError(\n            \"only list-like objects are allowed to be passed \"\n            f\"to isin(), you passed a `{type(values).__name__}`\"\n        )\n\n    if isinstance(values, (set, frozenset)) and len(values) > 0:\n        # GH#25507: for a set of values, membership can be tested directly\n        # via the set, avoiding an O(len(values)) materialization that\n        # otherwise dominates when comps is much smaller than values.\n        # Restrict to integer/bool comps (i.e. dtypes that cannot contain\n        # NaN), since Python set membership would mis-handle the case where\n        # both sides contain NaN values that are not identical.\n        if isinstance(comps, (ABCSeries, ABCIndex)):\n            comps_arr = comps._values\n        else:\n            comps_arr = comps\n        if (\n            isinstance(comps_arr, np.ndarray)\n            and comps_arr.ndim == 1","sourceCodeStart":512,"sourceCodeEnd":548,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/algorithms.py#L512-L548","documentation":"Raised by pandas.core.algorithms.isin when the values argument (the lookup set) is not list-like. This is the guard behind Series.isin(values)/Index.isin(values): a scalar lookup value cannot define membership, so the call is rejected.","triggerScenarios":"s.isin(5), idx.isin('a'), or any isin call where the right-hand side is a scalar; passing a single value where a sequence was expected.","commonSituations":"Off-by-one in data prep that yields a scalar instead of a list; users assuming isin accepts a single value; column lookups that collapse to a scalar via .iloc[0].","solutions":["Wrap the lookup value in a list: s.isin([5]).","For single-value membership, use s == value or s.eq(value).","Validate the lookup with is_list_like before calling isin."],"exampleFix":"# before\ns = pd.Series([1, 2, 3])\ns.isin(2)\n# after\ns.isin([2])","handlingStrategy":"type-guard","validationCode":"from pandas.api.types import is_list_like\n\ndef safe_isin_values(s, values):\n    if not is_list_like(values):\n        values = [values]\n    return s.isin(values)","typeGuard":"from pandas.api.types import is_list_like\n\ndef is_listlike(x) -> bool:\n    return is_list_like(x)","tryCatchPattern":null,"preventionTips":["Always wrap single lookup values in a list for isin.","Use s == value for single-value membership instead of isin.","Validate lookup sets with is_list_like before isin."],"tags":["isin","arraylike","validation","membership"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}