{"record":{"id":"5596348c7bb9934f","repo":"pola-rs/polars","slug":"pad-start-expects-a-str-given-a-qualified-ty","errorCode":null,"errorMessage":"\"pad_start\" expects a `str`, given a {qualified_type_name(fill_char)!r}","messagePattern":"\"pad_start\" expects a `str`, given a (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/expr/string.py","lineNumber":893,"sourceCode":"        --------\n        >>> df = pl.DataFrame({\"a\": [\"cow\", \"monkey\", \"hippopotamus\", None]})\n        >>> df.with_columns(padded=pl.col(\"a\").str.pad_start(8, \"*\"))\n        shape: (4, 2)\n        ┌──────────────┬──────────────┐\n        │ a            ┆ padded       │\n        │ ---          ┆ ---          │\n        │ str          ┆ str          │\n        ╞══════════════╪══════════════╡\n        │ cow          ┆ *****cow     │\n        │ monkey       ┆ **monkey     │\n        │ hippopotamus ┆ hippopotamus │\n        │ null         ┆ null         │\n        └──────────────┴──────────────┘\n        \"\"\"\n        length_pyexpr = parse_into_expression(length)\n        if not isinstance(fill_char, str):\n            msg = f'\"pad_start\" expects a `str`, given a {qualified_type_name(fill_char)!r}'\n            raise TypeError(msg)\n        return wrap_expr(self._pyexpr.str_pad_start(length_pyexpr, fill_char))\n\n    def pad_end(self, length: int | IntoExprColumn, fill_char: str = \" \") -> Expr:\n        \"\"\"\n        Pad the end of the string until it reaches the given length.\n\n        .. engine-support:: in-memory, streaming, distributed\n\n        Parameters\n        ----------\n        length\n            Pad the string until it reaches this length. Strings with length equal to or\n            greater than this value are returned as-is. Can be int or expression.\n        fill_char\n            The character to pad the string with.\n\n        See Also\n        --------","sourceCodeStart":875,"sourceCodeEnd":911,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/expr/string.py#L875-L911","documentation":"Expr.str.pad_start() requires `fill_char` to be exactly one str character; a non-string value (int, None, list, etc.) raises this TypeError naming the qualified type. Padding needs a character to fill with, so the type is checked in Python before the expression is built.","triggerScenarios":"Calling Expr.str.pad_start(length, fill_char=0) or fill_char=None or fill_char=['*'].","commonSituations":"Passing a numeric pad character without quotes; getting None from an unset config default; padding with unicode chars supplied through variables of the wrong type.","solutions":["Pass a single-character string: fill_char='0'.","Convert numeric fills: fill_char=str(0) — or simply write '0'.","If the value may be missing, default it: fill_char or ' '."],"exampleFix":"// before\npl.col('id').str.pad_start(10, 0)\n// after\npl.col('id').str.pad_start(10, '0')","handlingStrategy":"type-guard","validationCode":"if not isinstance(fill_char, str) or len(fill_char) != 1:\n    raise ValueError('fill_char must be a single-character string')","typeGuard":"def is_fill_char(v) -> bool:\n    return isinstance(v, str) and len(v) == 1","tryCatchPattern":"try:\n    expr = pl.col('s').str.pad_start(n, fill_char)\nexcept TypeError:\n    expr = pl.col('s').str.pad_start(n, ' ')","preventionTips":["Quote pad characters: '0' not 0.","Provide non-None defaults for optional fill_char in config handling.","Validate single-character str inputs at the boundary of your API."],"tags":["python","polars","type-error","arguments"],"backgroundTag":"invalid-argument-value","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"}