pandas-dev/pandas · error · TypeError
{cls.__name__}(...) must be called with a collection of some
Error message
{cls.__name__}(...) must be called with a collection of some kind, {data} was passed What it means
Raised by IntervalArray.__new__/_from_sequence when the data argument is a scalar (a single value) rather than a collection. Intervals arrays need a sequence of intervals or bounds; a scalar has no length/shape to build from. TypeError naming the class and the offending value.
Source
Thrown at pandas/core/arrays/interval.py:231
dtype: Dtype | None = None,
copy: bool = False,
verify_integrity: bool = True,
) -> Self:
data = extract_array(data, extract_numpy=True)
if isinstance(data, cls):
left: IntervalSide = data._left
right: IntervalSide = data._right
closed = closed or data.closed
dtype = IntervalDtype(left.dtype, closed=closed)
else:
# don't allow scalars
if is_scalar(data):
msg = (
f"{cls.__name__}(...) must be called with a collection "
f"of some kind, {data} was passed"
)
raise TypeError(msg)
# might need to convert empty or purely na data
data = _maybe_convert_platform_interval(data)
left, right, infer_closed = intervals_to_interval_bounds(
data, validate_closed=closed is None
)
if left.dtype == object:
left = lib.maybe_convert_objects(left)
right = lib.maybe_convert_objects(right)
closed = closed or infer_closed
left, right, dtype = cls._ensure_simple_new_inputs(
left,
right,
closed=closed,
copy=copy,
dtype=dtype,
)View on GitHub (pinned to 71959b8cb9)
Solutions
- Wrap the value in a collection: pd.arrays.IntervalArray([pd.Interval(0, 5)]).
- For a single interval use pd.Interval directly, not the array constructor.
- Verify the upstream expression returns a sequence before passing it in.
Example fix
# before pd.arrays.IntervalArray(pd.Interval(0, 5)) # after pd.arrays.IntervalArray([pd.Interval(0, 5)])
Defensive patterns
Strategy: type-guard
Validate before calling
def to_interval_array(data):
if pd.api.types.is_scalar(data):
raise TypeError('IntervalArray requires a collection, wrap the scalar in a list')
return pd.arrays.IntervalArray(data) Type guard
def is_collection(x) -> bool:
return not pd.api.types.is_scalar(x) and hasattr(x, '__iter__') Prevention
- Wrap single intervals in a list.
- Use pd.Interval for scalar use cases.
- Check is_scalar before array constructors.
When it happens
Trigger: pd.arrays.IntervalArray(pd.Interval(0, 5)); pd.IntervalIndex(0.5); passing a single Interval or number where a list/Series is expected.
Common situations: Forgetting to wrap a single value in a list; refactoring that yields a scalar from a previous step; treating a function meant for arrays as a scalar constructor.
Related errors
- dtype must be an IntervalDtype, got {dtype}
- DatetimeIndex has mixed timezones
- data is already tz-aware {inferred_tz}, unable to set specif
- Cannot construct {type(self).__name__} from scalar data. Pas
- cannot evaluate scalar only bool ops
AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07).
Data as JSON: /api/errors/3526585857b74fa1.
Report an issue: GitHub.