{"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/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/algorithms.py#L512-L548","documentation":"The isin() function's second argument (values — the set of values to test membership against) must be list-like. This is the companion check to the comps validation. While sets and frozensets are accepted (they get special fast-path handling later in the function), bare scalars, None, and other non-iterable types are rejected with a TypeError naming the actual type.","triggerScenarios":"Calling s.isin(some_variable) where some_variable is a scalar (int, float, str) rather than a collection. Passing None as the values argument. Using a variable that was expected to be a list/Series but is actually a single element due to upstream slicing or extraction logic.","commonSituations":"Extracting a single value from a column (df['col'].iloc[0]) and passing it to isin() instead of passing the column. Receiving a value from an API or config that is a scalar when a list was expected. Migration from SQL IN clauses where a single value is common.","solutions":["Wrap the scalar in a list before passing: s.isin([scalar_value]).","If the variable may be scalar or list-like, normalize it: vals = [vals] if not hasattr(vals, '__iter__') or isinstance(vals, str) else vals.","Use pd.Series() or np.array() to ensure the values argument is always array-like."],"exampleFix":"# before\ns.isin(lookup_value)\n\n# after\ns.isin([lookup_value])","handlingStrategy":"validation","validationCode":"from pandas.api.types import is_list_like\n\ndef safe_isin_values(series, lookup_values):\n    if not is_list_like(lookup_values):\n        lookup_values = [lookup_values]\n    return series.isin(lookup_values)","typeGuard":"from pandas.api.types import is_list_like\n\ndef is_valid_isin_values(value) -> bool:\n    return is_list_like(value) and not isinstance(value, (str, bytes))","tryCatchPattern":"try:\n    mask = s.isin(lookup)\nexcept TypeError as e:\n    if \"list-like\" in str(e):\n        mask = s.isin([lookup])\n    else:\n        raise","preventionTips":["Normalize lookup values to a list/array before passing to isin.","When extracting a value for lookup, use [df['col'].iloc[0]] not df['col'].iloc[0].","Write a unit test that checks isin with both single and multiple values."],"tags":["pandas","isin","type-validation","typeerror","array-like"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}