{"record":{"id":"11fba0d7f7c57064","repo":"pandas-dev/pandas","slug":"values-must-be-a-1d-list-like","errorCode":null,"errorMessage":"values must be a 1D list-like","messagePattern":"values must be a 1D list-like","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/numeric.py","lineNumber":188,"sourceCode":"        if inferred_type == \"boolean\" and dtype is None:\n            # object dtype array of bools\n            name = dtype_cls.__name__.strip(\"_\")\n            raise TypeError(f\"{values.dtype} cannot be converted to {name}\")\n\n    elif values.dtype.kind == \"b\" and checker(dtype):\n        # fastpath\n        mask = np.zeros(len(values), dtype=np.bool_)\n        if not copy:\n            values = np.asarray(values, dtype=default_dtype)\n        else:\n            values = np.array(values, dtype=default_dtype, copy=copy)\n\n    elif values.dtype.kind not in \"iuf\":\n        name = dtype_cls.__name__.strip(\"_\")\n        raise TypeError(f\"{values.dtype} cannot be converted to {name}\")\n\n    if values.ndim != 1:\n        raise TypeError(\"values must be a 1D list-like\")\n\n    if mask is None:\n        if values.dtype.kind in \"iu\":\n            # fastpath\n            mask = np.zeros(len(values), dtype=np.bool_)\n        elif values.dtype.kind == \"f\":\n            # np.isnan is faster than is_numeric_na() for floats\n            # github issue: #60066\n            if is_nan_na():\n                mask = np.isnan(values)\n            else:\n                mask = np.zeros(len(values), dtype=np.bool_)\n                if dtype_cls.__name__.strip(\"_\").startswith((\"I\", \"U\")):\n                    wrong = np.isnan(values)\n                    if wrong.any():\n                        raise ValueError(\"Cannot cast NaN value to Integer dtype.\")\n        elif is_nan_na():\n            mask = libmissing.is_numeric_na(values)","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/numeric.py#L170-L206","documentation":"Raised by _coerce_to_data_and_mask when values.ndim != 1. NumericArray (and all BaseMaskedArray subclasses) are strictly 1-D; passing a 2-D array or higher is rejected because the mask and data buffers must be 1-D aligned.","triggerScenarios":"pd.array(matrix, dtype='Int64') or IntegerArray(...) with a 2-D numpy array / nested list-like that asarray converts to ndim>=2.","commonSituations":"Passing a DataFrame.values or np.ndarray of shape (n,m) where a 1-D column was expected; nested lists interpreted as 2-D.","solutions":["Select a single column / flatten: pd.array(matrix[:, 0], dtype='Int64').","Construct one masked array per column and assemble into a DataFrame.","Use df = pd.DataFrame(matrix, dtype='Int64') for columnwise conversion."],"exampleFix":"// before\npd.array(np.array([[1, 2], [3, 4]]), dtype=\"Int64\")  # raises: values must be a 1D list-like\n\n// after\npd.array(np.array([[1, 2], [3, 4]])[:, 0], dtype=\"Int64\")","handlingStrategy":"validation","validationCode":"import numpy as np\n\ndef ensure_1d_values(values):\n    arr = np.asarray(values)\n    if arr.ndim != 1:\n        raise TypeError(f\"values must be 1D, got ndim={arr.ndim}\")\n    return arr","typeGuard":"def is_1d(values) -> bool:\n    import numpy as np\n    return np.asarray(values).ndim == 1","tryCatchPattern":"try:\n    arr = pd.array(values, dtype=\"Int64\")\nexcept TypeError as e:\n    if \"1D list-like\" in str(e):\n        arr = pd.array(np.asarray(values)[:, 0], dtype=\"Int64\")\n    else:\n        raise","preventionTips":["Select a single column before constructing a masked array.","Check values.ndim == 1 in ETL helpers.","Use pd.DataFrame(matrix, dtype='Int64') for multi-column conversion."],"tags":["numeric-array","ndim","validation"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}