pandas-dev/pandas · error · TypeError
only list-like objects are allowed to be passed to isin()…
Error message
only list-like objects are allowed to be passed to isin(), you passed a `{type(values).__name__}` What it means
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.
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.
Example fix
# before s.isin(lookup_value) # after s.isin([lookup_value])
Defensive patterns
Strategy: validation
Validate before calling
from pandas.api.types import is_list_like
def safe_isin_values(series, lookup_values):
if not is_list_like(lookup_values):
lookup_values = [lookup_values]
return series.isin(lookup_values) Type guard
from pandas.api.types import is_list_like
def is_valid_isin_values(value) -> bool:
return is_list_like(value) and not isinstance(value, (str, bytes)) Try / catch
try:
mask = s.isin(lookup)
except TypeError as e:
if "list-like" in str(e):
mask = s.isin([lookup])
else:
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- only list-like objects are allowed to be passed to isin()…
- requires a Series, Index, ExtensionArray, np.ndarray or…
- Only list-like objects or None are allowed to be passed to…
- Only np.ndarray, ExtensionArray, and Index objects are…
- pd.api.extensions.take requires a numpy.ndarray…
AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11).
Data as JSON: /api/errors/ecb7d85e0a8eb12f.
Report an issue: GitHub.
Appendix: 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 == 1View on GitHub (pinned to 3b7651241d)