{"record":{"id":"13b1d7ff26685cc2","repo":"pandas-dev/pandas","slug":"name-from-tuples-received-an-invalid-item-d","errorCode":null,"errorMessage":"{name}.from_tuples received an invalid item, {d}","messagePattern":"(.+?)\\.from_tuples received an invalid item, (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/interval.py","lineNumber":589,"sourceCode":"            left, right = [], []\n        else:\n            # ensure that empty data keeps input dtype\n            left = right = data\n\n        for d in data:\n            if not isinstance(d, tuple) and isna(d):\n                lhs = rhs = np.nan\n            else:\n                name = cls.__name__\n                try:\n                    # need list of length 2 tuples, e.g. [(0, 1), (1, 2), ...]\n                    lhs, rhs = d\n                except ValueError as err:\n                    msg = f\"{name}.from_tuples requires tuples of length 2, got {d}\"\n                    raise ValueError(msg) from err\n                except TypeError as err:\n                    msg = f\"{name}.from_tuples received an invalid item, {d}\"\n                    raise TypeError(msg) from err\n            left.append(lhs)\n            right.append(rhs)\n\n        return cls.from_arrays(left, right, closed, copy=False, dtype=dtype)\n\n    @classmethod\n    def _validate(cls, left, right, dtype: IntervalDtype) -> None:\n        \"\"\"\n        Verify that the IntervalArray is valid.\n\n        Checks that\n\n        * dtype is correct\n        * left and right match lengths\n        * left and right have the same missing values\n        * left is always below right\n        \"\"\"\n        if not isinstance(dtype, IntervalDtype):","sourceCodeStart":571,"sourceCodeEnd":607,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/interval.py#L571-L607","documentation":"Raised by `from_tuples` when unpacking an entry raises TypeError — meaning the entry is not iterable at all (e.g., an int, float, or scalar). Each item must be a length-2 tuple (or NaN/None). Fires at pandas/core/arrays/interval.py:589.","triggerScenarios":"`pd.IntervalIndex.from_tuples([0, 1, 2])`, `from_tuples([pd.NA, (1,2)])` (NA handled but a scalar int is not), or passing a flat list of numbers.","commonSituations":"Passing a list of scalars when intervals were intended; passing already-split single bounds; misreading API and passing a Series of values instead of tuples.","solutions":["If you have flat bounds, use `IntervalIndex.from_arrays(left_list, right_list)` instead.","Map scalars into pairs explicitly if that was the intent: `[(x, x) for x in data]`.","Filter non-tuple entries: `[t for t in data if isinstance(t, tuple)]`."],"exampleFix":"// before\npd.IntervalIndex.from_tuples(bounds_series)\n// after\npd.IntervalIndex.from_arrays(left_series, right_series)","handlingStrategy":"type-guard","validationCode":"def ensure_pair_list(data):\n    import numpy as np\n    out = []\n    for d in data:\n        if isinstance(d, tuple):\n            out.append(d)\n        elif d is None or (isinstance(d, float) and np.isnan(d)):\n            out.append((np.nan, np.nan))\n        else:\n            raise TypeError(f\"item is not a tuple: {d!r}\")\n    return out","typeGuard":"import numpy as np\n\ndef is_pair_or_na(d) -> bool:\n    return isinstance(d, tuple) or d is None or (isinstance(d, float) and np.isnan(d))","tryCatchPattern":"try:\n    ii = pd.IntervalIndex.from_tuples(data)\nexcept TypeError as e:\n    if \"invalid item\" in str(e):\n        # caller probably has flat bounds\n        raise TypeError(\"from_tuples needs tuples; use from_arrays(left, right) instead\") from e\n    raise","preventionTips":["Switch to from_arrays when your input is two flat sequences.","Reject scalar items upstream with an isinstance(t, tuple) check.","Map single scalars to pairs explicitly if degenerate intervals are intended."],"tags":["interval","from-tuples","input-validation","type-mismatch"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}