{"record":{"id":"34fe4acaaba217a1","repo":"pola-rs/polars","slug":"supplying-columns-param-value-is-mandatory-for-s","errorCode":null,"errorMessage":"supplying 'columns' param value is mandatory for sparklines","messagePattern":"supplying 'columns' param value is mandatory for sparklines","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/spreadsheet/_write_utils.py","lineNumber":302,"sourceCode":"\n\ndef _xl_inject_sparklines(\n    ws: Worksheet,\n    df: DataFrame,\n    table_start: tuple[int, int],\n    col: str,\n    *,\n    include_header: bool,\n    params: Sequence[str] | dict[str, Any],\n) -> None:\n    \"\"\"Inject sparklines into (previously-created) empty table columns.\"\"\"\n    from xlsxwriter.utility import xl_rowcol_to_cell\n\n    m: dict[str, Any] = {}\n    data_cols = params.get(\"columns\") if isinstance(params, dict) else params\n    if not data_cols:\n        msg = \"supplying 'columns' param value is mandatory for sparklines\"\n        raise ValueError(msg)\n    elif not _adjacent_cols(df, data_cols, min_max=m):\n        msg = \"sparkline data range/cols must all be adjacent\"\n        raise RuntimeError(msg)\n\n    spk_row, spk_col, _, _ = _xl_column_range(\n        df, table_start, col, include_header=include_header, as_range=False\n    )\n    data_start_col = table_start[1] + m[\"min\"][\"idx\"]\n    data_end_col = table_start[1] + m[\"max\"][\"idx\"]\n\n    if not isinstance(params, dict):\n        options = {}\n    else:\n        # strip polars-specific params before passing to xlsxwriter\n        options = {\n            name: val\n            for name, val in params.items()\n            if name not in (\"columns\", \"insert_after\", \"insert_before\")","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/io/spreadsheet/_write_utils.py#L284-L320","documentation":"Sparklines in write_excel need to know which contiguous columns of the table hold their data series. The sparkline params must include a 'columns' entry listing them; an empty or missing columns value raises ValueError.","triggerScenarios":"write_excel(..., sparklines={'name': {}}) or sparklines={'name': {'columns': []}} / params not a dict with usable 'columns' — i.e. data_cols resolves to empty.","commonSituations":"Configuring sparklines via config dicts where 'columns' was omitted or set to None/empty list; programmatically generated params with filtered-out column lists.","solutions":["Add 'columns' with the adjacent data columns: {'columns': ['jan','feb','mar']}","Ensure the list is non-empty and contains existing DataFrame column names","Use the tuple shorthand with explicit columns: {'columns': ['a','b'], 'type': 'line'}"],"exampleFix":"// before\nwrite_excel(wb, df, sparklines={'trend': {}})\n// after\nwrite_excel(wb, df, sparklines={'trend': {'columns': ['jan', 'feb', 'mar'], 'type': 'line'}})","handlingStrategy":"validation","validationCode":"cols = params.get('columns') if isinstance(params, dict) else params\nif not cols:\n    raise ValueError('sparkline params must include a non-empty columns list')","typeGuard":null,"tryCatchPattern":"try:\n    write_excel(wb, df, sparklines=spk)\nexcept ValueError as e:\n    if 'columns' in str(e) and 'sparkline' in str(e):\n        raise  # fix config: supply sparkline 'columns'","preventionTips":["Always specify sparkline 'columns' explicitly","Ensure sparkline source columns are adjacent in the df","Validate sparkline config dicts (non-empty columns) before write_excel"],"tags":["polars","excel","sparkline","validation"],"backgroundTag":"missing-required-argument","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"}