{"record":{"id":"97a0d16fdadece41","repo":"pola-rs/polars","slug":"unit-must-be-one-of-b-kb-mb-gb-tb","errorCode":null,"errorMessage":"`unit` must be one of {{'b', 'kb', 'mb', 'gb', 'tb'}}, got {unit!r}","messagePattern":"`unit` must be one of (.+?)\\}, got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/_utils/various.py","lineNumber":311,"sourceCode":"@overload\ndef scale_bytes(sz: Expr, unit: SizeUnit) -> Expr: ...\n\n\ndef scale_bytes(sz: int | Expr, unit: SizeUnit) -> int | float | Expr:\n    \"\"\"Scale size in bytes to other size units (eg: \"kb\", \"mb\", \"gb\", \"tb\").\"\"\"\n    if unit in {\"b\", \"bytes\"}:\n        return sz\n    elif unit in {\"kb\", \"kilobytes\"}:\n        return sz / 1024\n    elif unit in {\"mb\", \"megabytes\"}:\n        return sz / 1024**2\n    elif unit in {\"gb\", \"gigabytes\"}:\n        return sz / 1024**3\n    elif unit in {\"tb\", \"terabytes\"}:\n        return sz / 1024**4\n    else:\n        msg = f\"`unit` must be one of {{'b', 'kb', 'mb', 'gb', 'tb'}}, got {unit!r}\"\n        raise ValueError(msg)\n\n\ndef _cast_repr_strings_with_schema(\n    df: DataFrame, schema: dict[str, PolarsDataType | None]\n) -> DataFrame:\n    \"\"\"\n    Utility function to cast table repr/string values into frame-native types.\n\n    Parameters\n    ----------\n    df\n        Dataframe containing string-repr column data.\n    schema\n        DataFrame schema containing the desired end-state types.\n\n    Notes\n    -----\n    Table repr strings are less strict (or different) than equivalent CSV data, so need","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/pola-rs/polars/blob/5d8ebabf11caea54a5c29178a64a058762f49766/py-polars/src/polars/_utils/various.py#L293-L329","documentation":"ValueError raised by scale_bytes's unit guard: the unit is not one of b/bytes, kb, mb, gb, tb (or their long forms), so no scaling divisor applies. It is a validation guard at the terminal else of the unit ladder, echoing the invalid unit.","triggerScenarios":"Invalid size unit string.","commonSituations":"See trigger scenarios.","solutions":["Use unit one of 'b', 'kb', 'mb', 'gb', 'tb'."],"exampleFix":"pl.Config.set_fmt_table_cell_list_len(80)  # unit='mb'","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5d8ebabf11caea54a5c29178a64a058762f49766","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}