{"record":{"id":"3526585857b74fa1","repo":"pandas-dev/pandas","slug":"cls-name-must-be-called-with-a-collecti","errorCode":null,"errorMessage":"{cls.__name__}(...) must be called with a collection of some kind, {data} was passed","messagePattern":"(.+?)\\(\\.\\.\\.\\) must be called with a collection of some kind, (.+?) was passed","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/interval.py","lineNumber":231,"sourceCode":"        dtype: Dtype | None = None,\n        copy: bool = False,\n        verify_integrity: bool = True,\n    ) -> Self:\n        data = extract_array(data, extract_numpy=True)\n\n        if isinstance(data, cls):\n            left: IntervalSide = data._left\n            right: IntervalSide = data._right\n            closed = closed or data.closed\n            dtype = IntervalDtype(left.dtype, closed=closed)\n        else:\n            # don't allow scalars\n            if is_scalar(data):\n                msg = (\n                    f\"{cls.__name__}(...) must be called with a collection \"\n                    f\"of some kind, {data} was passed\"\n                )\n                raise TypeError(msg)\n\n            # might need to convert empty or purely na data\n            data = _maybe_convert_platform_interval(data)\n            left, right, infer_closed = intervals_to_interval_bounds(\n                data, validate_closed=closed is None\n            )\n            if left.dtype == object:\n                left = lib.maybe_convert_objects(left)\n                right = lib.maybe_convert_objects(right)\n            closed = closed or infer_closed\n\n            left, right, dtype = cls._ensure_simple_new_inputs(\n                left,\n                right,\n                closed=closed,\n                copy=copy,\n                dtype=dtype,\n            )","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/interval.py#L213-L249","documentation":"Raised by `IntervalArray.__new__` (and `_simple_new` paths) when the `data` argument is a scalar. IntervalArray requires a collection (array-like of intervals, or arrays for from_arrays) because it represents a sequence; a single Interval must be wrapped in a list. The check uses `is_scalar(data)` before attempting platform conversion.","triggerScenarios":"`pd.arrays.IntervalArray(pd.Interval(0, 1))` (passing one Interval object); `pd.IntervalIndex(5)`; passing a bare scalar like an int or Timestamp where a list is expected.","commonSituations":"Programmatically building an interval array in a loop where the variable happens to be a single Interval rather than a list; refactoring from scalar handling to vectorised code; user confusion between Interval (scalar type) and IntervalArray/Index.","solutions":["Wrap the scalar in a list: `pd.arrays.IntervalArray([pd.Interval(0, 1)])`.","If you have left/right bounds, use `IntervalArray.from_arrays(left, right)` instead of passing intervals.","Build the collection upstream and only call IntervalArray once you have >=1 element list."],"exampleFix":"# before\narr = pd.arrays.IntervalArray(pd.Interval(0, 1))\n\n# after\narr = pd.arrays.IntervalArray([pd.Interval(0, 1)])\n# or\narr = pd.arrays.IntervalArray.from_arrays([0], [1])","handlingStrategy":"type-guard","validationCode":"import pandas as pd\nfrom pandas.api.types import is_scalar\n\ndef to_interval_array(data):\n    if is_scalar(data):\n        data = [data]\n    return pd.arrays.IntervalArray(data)","typeGuard":"from collections.abc import Iterable, Sized\nfrom pandas.api.types import is_scalar\n\ndef is_interval_collection(data) -> bool:\n    return not is_scalar(data) and isinstance(data, (Iterable, Sized))","tryCatchPattern":"try:\n    arr = pd.arrays.IntervalArray(data)\nexcept TypeError as e:\n    if 'must be called with a collection' in str(e):\n        arr = pd.arrays.IntervalArray([data])\n    else:\n        raise","preventionTips":["Always wrap a single Interval in a list before passing to IntervalArray.","Use from_arrays(left, right) when you have bounds rather than Interval objects.","Type-check upstream containers in pipeline code."],"tags":["interval","interval-array","scalar-argument","type-error"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}