{"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":"validation","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/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/interval.py#L571-L607","documentation":"Raised in the same from_tuples loop when unpacking `lhs, rhs = d` raises TypeError rather than ValueError — i.e. `d` is not iterable/unpackable at all (an int, None that is not NA-detected, a non-iterable object). NA values are handled before unpacking; anything else that is not a tuple of two triggers this.","triggerScenarios":"`IntervalArray.from_tuples([42])`; `from_tuples([None])` where None is not treated as NA by `isna`; `from_tuples([object()])`.","commonSituations":"Dirty data where some rows are scalars instead of pairs; user passes a list of mixed intervals and bare numbers.","solutions":["Filter or coerce non-tuple items: keep only tuples of length 2 (or recognised NA).","Replace bare scalars with explicit NA: `pd.NA` or `np.nan` so the NA branch handles them.","Build with `from_arrays` from two parallel lists derived from your data instead of from_tuples."],"exampleFix":"# before\npd.arrays.IntervalArray.from_tuples([42, (0,1)])\n\n# after - normalise entries first\nclean = [x if isinstance(x, tuple) and len(x) == 2 else pd.NA for x in [42, (0,1)]]\npd.arrays.IntervalArray.from_tuples(clean)","handlingStrategy":"validation","validationCode":"import pandas as pd\n\ndef coerce_to_pairs(data):\n    out = []\n    for d in data:\n        if isinstance(d, tuple) and len(d) == 2:\n            out.append(d)\n        elif pd.isna(d):\n            out.append(pd.NA)\n        else:\n            out.append(pd.NA)\n    return out","typeGuard":"import pandas as pd\nfrom collections.abc import Iterable\n\ndef all_unpackable_or_na(data) -> bool:\n    for d in data:\n        if pd.isna(d):\n            continue\n        if not (isinstance(d, tuple) and len(d) == 2):\n            return False\n    return True","tryCatchPattern":"try:\n    arr = pd.arrays.IntervalArray.from_tuples(data)\nexcept TypeError as e:\n    if 'invalid item' in str(e):\n        clean = [d if isinstance(d, tuple) and len(d) == 2 else pd.NA for d in data]\n        arr = pd.arrays.IntervalArray.from_tuples(clean)\n    else:\n        raise","preventionTips":["Pre-filter rows so every item is a length-2 tuple or recognised NA.","Use from_arrays with two parallel lists when source data is irregular.","Normalise bare scalars to pd.NA upstream."],"tags":["interval","from-tuples","non-iterable","type-error"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}