{"record":{"id":"ead5b3c50bf2bf03","repo":"pola-rs/polars","slug":"array-constructor-is-missing-the-required-argument","errorCode":null,"errorMessage":"Array constructor is missing the required argument `shape`","messagePattern":"Array constructor is missing the required argument `shape`","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/datatypes/classes.py","lineNumber":1247,"sourceCode":"    size: int\n    shape: tuple[int, ...]\n\n    @removed_parameters(\n        RemovedParameter(\n            name=\"width\",\n            deprecated_in=\"0.20.31\",\n            removed_in=\"2.0\",\n            hint=\"use `shape` instead.\",\n        )\n    )\n    def __init__(\n        self,\n        inner: PolarsDataType | PythonDataType,\n        shape: int | tuple[int, ...] | None = None,\n    ) -> None:\n        if shape is None:\n            msg = \"Array constructor is missing the required argument `shape`\"\n            raise TypeError(msg)\n\n        inner_parsed = polars.datatypes.parse_into_dtype(inner)\n        inner_shape = inner_parsed.shape if isinstance(inner_parsed, Array) else ()\n\n        if isinstance(shape, int):\n            self.inner = inner_parsed\n            self.size = shape\n            self.shape = (shape,) + inner_shape\n\n        elif isinstance(shape, tuple) and isinstance(shape[0], int):  # type: ignore[redundant-expr]\n            if len(shape) > 1:\n                inner_parsed = Array(inner_parsed, shape[1:])\n\n            self.inner = inner_parsed\n            self.size = shape[0]\n            self.shape = shape + inner_shape\n\n        else:","sourceCodeStart":1229,"sourceCodeEnd":1265,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/datatypes/classes.py#L1229-L1265","documentation":"pl.Array requires an explicit `shape` (a fixed-width nested type, unlike List). Since 1.x the constructor no longer infers shape from data, so constructing pl.Array(inner) without shape raises this TypeError.","triggerScenarios":"pl.Array(pl.Int32) with no shape argument; pl.Array(pl.Float64, shape=None) explicitly; copying old pre-1.0 code where width was optional.","commonSituations":"Upgrading polars across versions where the Array signature changed; converting pl.List usages to pl.Array and forgetting the width.","solutions":["Pass shape as an int for 1-D: pl.Array(pl.Int32, 3)","Pass a tuple for nested shapes: pl.Array(pl.Int32, (2, 3))","Use pl.List instead if the width is truly variable"],"exampleFix":"// before\npl.Array(pl.Int32)\n// after\npl.Array(pl.Int32, shape=3)","handlingStrategy":"type-guard","validationCode":"def make_array(inner, shape=None):\n    if shape is None:\n        raise ValueError('pl.Array requires an explicit shape')\n    return pl.Array(inner, shape=shape)","typeGuard":null,"tryCatchPattern":"try:\n    dtype = pl.Array(inner, shape)\nexcept TypeError as e:\n    if 'shape' in str(e):\n        dtype = pl.List(inner)  # variable width fallback\n    else:\n        raise","preventionTips":["Always pass shape (int or tuple) when constructing pl.Array","Use pl.List when the element count is not fixed","Check the polars changelog when upgrading — Array's signature changed over versions"],"tags":["polars","array","shape","type-error"],"backgroundTag":"missing-required-argument","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}