{"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/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/numeric.py#L170-L206","documentation":"Raised by pandas.core.arrays.numeric._coerce_to_data_and_mask when the input values, after being coerced to a NumPy array, have more than one dimension (values.ndim != 1). IntegerArray/FloatingArray are 1-D extension arrays backed by a single data ndarray plus a boolean mask, so multi-dimensional data is rejected at construction. The check runs after dtype coercion, so even a valid numeric 2-D array (e.g. a matrix) triggers it.","triggerScenarios":"Calling pd.array([[1, 2], [3, 4]], dtype='Int64'), constructing IntegerArray/FloatingArray from a 2-D numpy array, or passing a DataFrame column block (2-D) to a masked-numeric constructor. Also reachable via astype('Int64') on a DataFrame (per-column is fine, but internal 2-D blocks route through here).","commonSituations":"Passing a matrix/list-of-lists where a flat vector was intended; reshaping data upstream and forgetting to flatten; converting a wide DataFrame slice instead of a single Series.","solutions":["Flatten the input before construction, e.g. np.ravel(values) or values.reshape(-1).","Operate column-by-column on a DataFrame (each Series is 1-D) instead of passing the whole frame to a masked array.","Use pd.DataFrame for genuinely 2-D data rather than a 1-D extension array."],"exampleFix":"# before\npd.array([[1, 2], [3, 4]], dtype='Int64')  # raises\n\n# after\npd.array(np.array([[1, 2], [3, 4]]).ravel(), dtype='Int64')","handlingStrategy":"validation","validationCode":"import numpy as np\n\ndef to_masked_numeric(values, dtype):\n    arr = np.asarray(values)\n    if arr.ndim != 1:\n        raise ValueError(f'expected 1-D input, got ndim={arr.ndim}')\n    return pd.array(arr, dtype=dtype)","typeGuard":"def is_1d_arraylike(obj) -> bool:\n    import numpy as np\n    return hasattr(obj, 'ndim') and np.asarray(obj).ndim == 1","tryCatchPattern":"try:\n    pd.array(values, dtype='Int64')\nexcept TypeError as e:\n    if '1D list-like' in str(e):\n        values = np.asarray(values).ravel()\n        pd.array(values, dtype='Int64')\n    else:\n        raise","preventionTips":["Always flatten matrices with .ravel() or .reshape(-1) before passing to a 1-D array constructor.","Prefer operating on DataFrame columns (Series) rather than 2-D slices when constructing extension arrays.","Validate ndim==1 in your data-loading layer."],"tags":["pandas","masked-array","numeric","dtype","shape"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}