{"record":{"id":"74ed64d417ef2f17","repo":"pandas-dev/pandas","slug":"only-list-like-objects-are-allowed-to-be-passed-to","errorCode":null,"errorMessage":"only list-like objects are allowed to be passed to isin(), you passed a `{type(comps).__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":525,"sourceCode":"_FLOAT64_INT_EXACT_MAX = 2**53\n\n\ndef isin(comps: ListLike, values: ListLike) -> npt.NDArray[np.bool_]:\n    \"\"\"\n    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","sourceCodeStart":507,"sourceCodeEnd":543,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/algorithms.py#L507-L543","documentation":"Raised by pandas.core.algorithms.isin when the comps argument (the values being tested for membership) is not list-like. Series/Index.isin route their underlying values through this function; a non-list-like comps cannot be tested element-wise, so pandas rejects it up front.","triggerScenarios":"Calling the internal pd.core.algorithms.isin with a scalar comps; indirectly, paths that build the comps from a scalar before reaching isin.","commonSituations":"Calling isin via the internal API with accidentally-scalar data; refactors that pass a single value instead of a sequence as the left-hand side.","solutions":["Pass a list-like for comps (wrap a scalar in a list).","Prefer the public Series.isin(values) / Index.isin(values) which validate at the boundary.","Add an is_list_like check before invoking the internal function."],"exampleFix":"# before\nfrom pandas.core.algorithms import isin\nmask = isin(5, [1, 2, 5])\n# after\nmask = isin([5], [1, 2, 5])","handlingStrategy":"type-guard","validationCode":"from pandas.api.types import is_list_like\n\ndef safe_isin(comps, values):\n    if not is_list_like(comps):\n        raise TypeError(f'comps must be list-like, got {type(comps).__name__}')\n    return pd.core.algorithms.isin(comps, 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 pass a list-like for the comps (left) side of isin.","Prefer the public Series.isin / Index.isin over the internal function.","Validate with is_list_like at boundaries."],"tags":["isin","arraylike","validation","membership"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}