{"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":935,"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":917,"sourceCodeEnd":953,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/expr/string.py#L917-L953","documentation":"Expr.str.pad_end() requires `fill_char` to be a str; any other type raises this TypeError with the qualified type name of what was given. Like pad_start, the fill character is validated client-side before building the expression.","triggerScenarios":"Calling Expr.str.pad_end(length, fill_char=0), fill_char=None, or a collection such as fill_char=['.'] .","commonSituations":"Numeric fill values from config; None defaults leaking in; copying pad_start code and swapping the argument order so a non-str lands in fill_char.","solutions":["Pass a single-character string, e.g. fill_char=' '.","Convert the value: fill_char=str(value) if it is a scalar char.","Guard optional values with a default: fill_char or ' '."],"exampleFix":"// before\npl.col('name').str.pad_end(20, '-')\npl.col('name').str.pad_end(20, 0)\n// after\npl.col('name').str.pad_end(20, '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_end(n, fill_char)\nexcept TypeError:\n    expr = pl.col('s').str.pad_end(n, ' ')","preventionTips":["Double-check argument order when adapting pad_start code to pad_end.","Coerce scalars with str() before passing as fill_char.","Default missing values: fill_char or ' '."],"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"}