pandas-dev/pandas · error · TypeError

only list-like objects are allowed to be passed to isin(), y

Error message

only list-like objects are allowed to be passed to isin(), you passed a `{type(values).__name__}`

What it means

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.

Source

Thrown at pandas/core/algorithms.py:530

    Compute the isin boolean array.

    Parameters
    ----------
    comps : list-like
    values : list-like

    Returns
    -------
    ndarray[bool]
        Same length as `comps`.
    """
    if not is_list_like(comps):
        raise TypeError(
            "only list-like objects are allowed to be passed "
            f"to isin(), you passed a `{type(comps).__name__}`"
        )
    if not is_list_like(values):
        raise TypeError(
            "only list-like objects are allowed to be passed "
            f"to isin(), you passed a `{type(values).__name__}`"
        )

    if isinstance(values, (set, frozenset)) and len(values) > 0:
        # GH#25507: for a set of values, membership can be tested directly
        # via the set, avoiding an O(len(values)) materialization that
        # otherwise dominates when comps is much smaller than values.
        # Restrict to integer/bool comps (i.e. dtypes that cannot contain
        # NaN), since Python set membership would mis-handle the case where
        # both sides contain NaN values that are not identical.
        if isinstance(comps, (ABCSeries, ABCIndex)):
            comps_arr = comps._values
        else:
            comps_arr = comps
        if (
            isinstance(comps_arr, np.ndarray)
            and comps_arr.ndim == 1

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Wrap the lookup value in a list: s.isin([5]).
  2. For single-value membership, use s == value or s.eq(value).
  3. Validate the lookup with is_list_like before calling isin.

Example fix

# before
s = pd.Series([1, 2, 3])
s.isin(2)
# after
s.isin([2])
Defensive patterns

Strategy: type-guard

Validate before calling

from pandas.api.types import is_list_like

def safe_isin_values(s, values):
    if not is_list_like(values):
        values = [values]
    return s.isin(values)

Type guard

from pandas.api.types import is_list_like

def is_listlike(x) -> bool:
    return is_list_like(x)

Prevention

When it happens

Trigger: 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.

Common situations: 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].

Related errors


AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07). Data as JSON: /api/errors/ecb7d85e0a8eb12f. Report an issue: GitHub.