{"record":{"id":"a436fb73f7b8f1bc","repo":"pola-rs/polars","slug":"cannot-use-include-key-without-specifying-key","errorCode":null,"errorMessage":"cannot use 'include_key' without specifying 'key'","messagePattern":"cannot use 'include_key' without specifying 'key'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/partition.py","lineNumber":115,"sourceCode":"    ) -> None:\n        msg = \"`PartitionBy` functionality is considered unstable\"\n        issue_unstable_warning(msg)\n\n        if (\n            key is None\n            and max_rows_per_file is None\n            and approximate_bytes_per_file == \"auto\"\n        ):\n            msg = (\n                \"at least one of \"\n                \"('key', 'max_rows_per_file', 'approximate_bytes_per_file') \"\n                \"must be specified for PartitionBy\"\n            )\n            raise ValueError(msg)\n\n        if key is None and include_key is not None:\n            msg = \"cannot use 'include_key' without specifying 'key'\"\n            raise ValueError(msg)\n\n        base_path = str(base_path)\n\n        if approximate_bytes_per_file == \"auto\":\n            approximate_bytes_per_file = (\n                4_294_967_295 if max_rows_per_file is None else None\n            )\n\n        if approximate_bytes_per_file is None:\n            approximate_bytes_per_file = (1 << 64) - 1\n\n        self._pl_partition_by = _PartitionByInner(\n            base_path=base_path,\n            file_path_provider=file_path_provider,\n            key=_parse_to_pyexpr_list(key) if key is not None else None,\n            include_key=include_key,\n            max_rows_per_file=max_rows_per_file,\n            approximate_bytes_per_file=approximate_bytes_per_file,","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/io/partition.py#L97-L133","documentation":"include_key controls whether partition-key columns are repeated inside the output data, so it only makes sense when a key is defined. Passing include_key without key is contradictory and raises ValueError in PartitionBy.__init__.","triggerScenarios":"pl.PartitionBy(base_path, key=None, include_key=True/False) — any non-None include_key while key is None.","commonSituations":"Copy-pasting include_key=True from keyed partition configs; templated code that always passes include_key even when key is unset.","solutions":["Specify a key alongside include_key: pl.PartitionBy('out/', key='col', include_key=False)","Remove the include_key argument when there is no key","Fix the variable feeding key so it is not None"],"exampleFix":"// before\npl.PartitionBy('out/', include_key=False)\n// after\npl.PartitionBy('out/', key='date', include_key=False)","handlingStrategy":"validation","validationCode":"if include_key is not None and key is None:\n    raise ValueError('include_key requires a partition key')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only pass include_key together with key","Gate include_key behind key presence in templated code","Prefer include_key=False explicitly only when key exists"],"tags":["polars","partitioning","validation"],"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"}