{"record":{"id":"aacc10b76bb875f0","repo":"pola-rs/polars","slug":"pad-end-expects-a-str-given-a-qualified-type","errorCode":null,"errorMessage":"\"pad_end\" expects a `str`, given a {qualified_type_name(fill_char)!r}","messagePattern":"\"pad_end\" expects a `str`, given a (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/expr/string.py","lineNumber":941,"sourceCode":"        >>> df.with_columns(padded=pl.col(\"a\").str.pad_end(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 = (\n                f'\"pad_end\" expects a `str`, given a {qualified_type_name(fill_char)!r}'\n            )\n            raise TypeError(msg)\n        return wrap_expr(self._pyexpr.str_pad_end(length_pyexpr, fill_char))\n\n    def zfill(self, length: int | IntoExprColumn) -> Expr:\n        \"\"\"\n        Pad the start of the string with zeros until it reaches the given length.\n\n        A sign prefix (`-`) is handled by inserting the padding after the sign\n        character rather than before.\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\n            or greater than this value are returned as-is.\n\n        See Also","sourceCodeStart":923,"sourceCodeEnd":959,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/expr/string.py#L923-L959","documentation":"Raised in the Python layer of Expr.str.pad_end before execution: the fill_char argument must be a plain str. Any other type (int, bytes, None, an Expr) triggers a TypeError naming the qualified type. Padding is applied on the right side of the string; the fill character itself must be a literal single-character string.","triggerScenarios":"Calling pl.col('s').str.pad_end(10, fill_char=0), fill_char=None, fill_char=b'-', or passing a column expression as fill_char (only length may be an expression; fill_char must be a literal str).","commonSituations":"Right-aligning numeric codes with '0' but passing the integer; bytes fill characters from serialized configs; None defaults from optional parameters; confusing the expression-accepting length parameter with the literal-only fill_char parameter.","solutions":["Pass fill_char as a str, e.g. fill_char='0' or fill_char='-'","Convert values from config/data with str(value) before calling","For right-aligned zero padding use .str.zfill(length) instead","If the fill char must vary per row, preprocess via map_batches; the API does not support it"],"exampleFix":"# before\npl.col('code').str.pad_end(6, fill_char=0)\n\n# after\npl.col('code').str.pad_end(6, fill_char='0')\n# or for zero fill:\npl.col('code').str.zfill(6)","handlingStrategy":"type-guard","validationCode":"fill_char = '-'\nassert isinstance(fill_char, str), 'fill_char must be str'\nexpr = pl.col('s').str.pad_end(10, fill_char=fill_char)","typeGuard":"def is_valid_fill_char(x: object) -> bool:\n    return isinstance(x, str) and len(x) >= 1","tryCatchPattern":null,"preventionTips":["Treat fill_char as a literal, never an expression","Decode bytes values to str where they enter your program","Prefer .str.zfill when padding with zeros","Run mypy/pyright so the str annotation catches bad call sites"],"tags":["polars","python","typeerror","string","argument-validation"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}