{"record":{"id":"57f6628d3d3cc3d5","repo":"pola-rs/polars","slug":"cannot-specify-both-columns-and-read-options-c","errorCode":null,"errorMessage":"cannot specify both `columns` and `read_options[\"columns\"]`","messagePattern":"cannot specify both `columns` and `read_options\\[\"columns\"\\]`","errorType":"validation","errorClass":"ParameterCollisionError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/spreadsheet/functions.py","lineNumber":773,"sourceCode":"        read_options[\"schema_sample_rows\"] = infer_schema_length\n        if has_header is False and \"header_row\" not in read_options:\n            read_options[\"header_row\"] = None\n\n    elif engine == \"xlsx2csv\":\n        if (\"columns\" in read_options) and columns:\n            msg = 'cannot specify both `columns` and `read_options[\"columns\"]`'\n            raise ParameterCollisionError(msg)\n        elif (\n            \"has_header\" in read_options\n            and read_options[\"has_header\"] is not has_header\n        ):\n            msg = 'the values of `has_header` and `read_options[\"has_header\"]` are not compatible'\n            raise ParameterCollisionError(msg)\n        elif (\"infer_schema_length\" in read_options) and (\n            infer_schema_length != N_INFER_DEFAULT\n        ):\n            msg = 'cannot specify both `infer_schema_length` and `read_options[\"infer_schema_length\"]`'\n            raise ParameterCollisionError(msg)\n\n        read_options[\"infer_schema_length\"] = infer_schema_length\n        if \"has_header\" not in read_options:\n            read_options[\"has_header\"] = has_header\n    else:\n        read_options[\"infer_schema_length\"] = infer_schema_length\n        read_options[\"has_header\"] = has_header\n\n    return read_options\n\n\ndef _get_sheet_names(\n    sheet_id: int | Sequence[int] | None,\n    sheet_name: str | Sequence[str] | None,\n    table_name: str | None,\n    worksheets: list[dict[str, Any]],\n) -> tuple[list[str], bool]:\n    \"\"\"Establish sheets to read; indicate if we are returning a dict frames.\"\"\"","sourceCodeStart":755,"sourceCodeEnd":791,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/io/spreadsheet/functions.py#L755-L791","documentation":"With the xlsx2csv engine, top-level `columns` and `read_options[\"columns\"]` both select output columns; passing both (with a truthy `columns`) is ambiguous, so `_get_read_options` raises `ParameterCollisionError`.","triggerScenarios":"`pl.read_excel(..., engine='xlsx2csv', columns=['a'], read_options={'columns': 'a,b'})` — any call where both are supplied.","commonSituations":"Mixing the newer top-level `columns` API with legacy read_options-based column selection; templated configs that always inject a 'columns' key.","solutions":["Use only the top-level `columns=` argument and remove the key from read_options","Or keep `read_options['columns']` and omit `columns=`","Guard shared read_options dicts to strip engine-specific keys before merging"],"exampleFix":"// before\npl.read_excel(f, engine='xlsx2csv', columns=['a'], read_options={'columns': 'a'})\n// after\npl.read_excel(f, engine='xlsx2csv', columns=['a'])","handlingStrategy":"validation","validationCode":"assert not (columns and 'columns' in read_options), 'columns conflict'","typeGuard":null,"tryCatchPattern":"from polars.exceptions import ParameterCollisionError\ntry:\n    pl.read_excel(f, engine='xlsx2csv', columns=cols, read_options=ro)\nexcept ParameterCollisionError:\n    ro.pop('columns', None)\n    df = pl.read_excel(f, engine='xlsx2csv', columns=cols, read_options=ro)","preventionTips":["Use top-level columns= exclusively","Reject/strip 'columns' from user-supplied read_options at config load","Add an assertion in wrapper helpers"],"tags":["python","polars","parameter-collision","excel"],"backgroundTag":"conflicting-config-options","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"}