{"record":{"id":"091a12eba99b574e","repo":"pola-rs/polars","slug":"invalid-dtype-for-zeros-found-dtype","errorCode":null,"errorMessage":"invalid dtype for `zeros`; found {dtype}","messagePattern":"invalid dtype for `zeros`; found (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/functions/repeat.py","lineNumber":299,"sourceCode":"    See Also\n    --------\n    repeat\n    lit\n\n    Examples\n    --------\n    >>> pl.zeros(3, pl.Int8, eager=True)\n    shape: (3,)\n    Series: 'zeros' [i8]\n    [\n        0\n        0\n        0\n    ]\n    \"\"\"\n    if (zero := _one_or_zero_by_dtype(0, dtype)) is None:\n        msg = f\"invalid dtype for `zeros`; found {dtype}\"\n        raise TypeError(msg)\n\n    return repeat(zero, n=n, dtype=dtype, eager=eager).alias(\"zeros\")\n","sourceCodeStart":281,"sourceCodeEnd":302,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/functions/repeat.py#L281-L302","documentation":"Raised by pl.zeros when the requested dtype has no sensible 'zero' representation. Supported dtypes are the integer and float families, Boolean, String (Utf8), Decimal, and List/Array of those (same lookup as ones); any other dtype (Date, Datetime, Duration, Categorical, ...) fails.","triggerScenarios":"pl.zeros(3, pl.Datetime('us')); pl.zeros(3, dtype=pl.Duration); pl.zeros(3, pl.Enum(['a','b'])); List inner dtype that is temporal.","commonSituations":"Prealloculating null-free placeholder columns for temporal schemas; masking idioms ported from numpy; writing generic 'make empty-ish column of dtype X' helpers that route through zeros.","solutions":["Create zeros with a supported dtype then cast: pl.zeros(3, pl.Int64).cast(pl.Datetime('us'))","Use pl.repeat(0, n, dtype=...) or pl.repeat(value, ...) for values polars can type","For temporals, prefer pl.repeat + cast or fill_null on a literal expression"],"exampleFix":"// before\npl.zeros(3, pl.Datetime('us'), eager=True)\n// after\npl.zeros(3, pl.Int64, eager=True).cast(pl.Datetime('us'))","handlingStrategy":"validation","validationCode":"from polars.datatypes.group import INTEGER_DTYPES, FLOAT_DTYPES\nfrom polars import Boolean, Utf8, Decimal, List, Array\n\nzeros_ok = dtype in INTEGER_DTYPES or dtype in FLOAT_DTYPES or dtype in (Boolean, Utf8) or isinstance(dtype, (Decimal, List, Array))","typeGuard":"def is_fillable_dtype(dtype) -> bool:\n    from polars.datatypes.group import INTEGER_DTYPES, FLOAT_DTYPES\n    from polars import Boolean, Utf8, Decimal, List, Array\n    return (dtype in INTEGER_DTYPES or dtype in FLOAT_DTYPES\n            or dtype in (Boolean, Utf8) or isinstance(dtype, (Decimal, List, Array)))","tryCatchPattern":"try:\n    s = pl.zeros(3, dtype, eager=True)\nexcept TypeError:\n    s = pl.zeros(3, pl.Int64, eager=True).cast(dtype)","preventionTips":["For typed placeholder columns use pl.repeat/lit + cast instead of zeros","Validate schema dtypes against the supported set in fixture factories"],"tags":["polars","zeros","dtype-validation","initialization"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}