{"record":{"id":"ed443e76c869fa56","repo":"pandas-dev/pandas","slug":"name-from-tuples-requires-tuples-of-length-2-go","errorCode":null,"errorMessage":"{name}.from_tuples requires tuples of length 2, got {d}","messagePattern":"(.+?)\\.from_tuples requires tuples of length 2, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/interval.py","lineNumber":586,"sourceCode":"        Length: 2, dtype: interval[int64, right]\n        \"\"\"\n        if len(data):\n            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","sourceCodeStart":568,"sourceCodeEnd":604,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/interval.py#L568-L604","documentation":"Raised inside `_from_sequence_of_custom` / the from_tuples path when iterating `data` and unpacking `lhs, rhs = d` raises a ValueError — i.e. the tuple does not have exactly 2 elements. Each item must be a length-2 tuple (or NA).","triggerScenarios":"`IntervalArray.from_tuples([(0,1,2)])` (length 3); `from_tuples([(0,)])` (length 1); tuples built by zipping three iterables.","commonSituations":"Malformed upstream data producing 3-tuples; bugs in tuple construction; passing rows of a 3+ column DataFrame as the sequence.","solutions":["Sanitise the tuples to length 2 before passing: `[t[:2] for t in data]`.","If you have left/right/mid, pick the two you want explicitly and use `from_arrays`.","Validate `all(len(t) == 2 for t in data)` before calling from_tuples."],"exampleFix":"# before\npd.arrays.IntervalArray.from_tuples([(0,1,2), (3,4,5)])\n\n# after\npd.arrays.IntervalArray.from_tuples([(0,1), (3,4)])\n# or slice to first two\npd.arrays.IntervalArray.from_tuples([t[:2] for t in [(0,1,2),(3,4,5)]])","handlingStrategy":"validation","validationCode":"def clean_tuples(data):\n    out = []\n    for t in data:\n        if isinstance(t, tuple) and len(t) == 2:\n            out.append(t)\n        else:\n            out.append((pd.NA, pd.NA))\n    return out","typeGuard":"def all_pairs(data) -> bool:\n    return all(isinstance(t, tuple) and len(t) == 2 for t in data)","tryCatchPattern":"try:\n    arr = pd.arrays.IntervalArray.from_tuples(data)\nexcept ValueError as e:\n    if 'requires tuples of length 2' in str(e):\n        arr = pd.arrays.IntervalArray.from_tuples([t[:2] for t in data])\n    else:\n        raise","preventionTips":["Validate `len(t) == 2` for every tuple before calling from_tuples.","Build pairs with zip(left, right) to guarantee length 2.","Avoid forwarding raw DataFrame rows that may have 3+ columns."],"tags":["interval","from-tuples","tuple-length","value-error"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}