{"record":{"id":"130ba817e929daa5","repo":"pola-rs/polars","slug":"infer-schema-length-should-be-positive","errorCode":null,"errorMessage":"'infer_schema_length' should be positive","messagePattern":"'infer_schema_length' should be positive","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/ndjson.py","lineNumber":325,"sourceCode":"        Include the path of the source file(s) as a column with this name.\n    \"\"\"\n    sources: list[str] | list[Path] | list[IO[str]] | list[IO[bytes]] = []\n    if isinstance(source, (str, Path)):\n        source = normalize_filepath(source, check_not_directory=False)\n    elif isinstance(source, list):\n        if is_path_or_str_sequence(source):\n            sources = [\n                normalize_filepath(source, check_not_directory=False)\n                for source in source\n            ]\n        else:\n            sources = source\n\n        source = None  # type: ignore[assignment]\n\n    if infer_schema_length == 0:\n        msg = \"'infer_schema_length' should be positive\"\n        raise ValueError(msg)\n\n    credential_provider_builder = _init_credential_provider_builder(\n        credential_provider, source, storage_options, \"scan_ndjson\"\n    )\n\n    del credential_provider\n\n    pylf = PyLazyFrame.new_from_ndjson(\n        source,\n        sources,\n        infer_schema_length=infer_schema_length,\n        schema=schema,\n        schema_overrides=schema_overrides,\n        batch_size=batch_size,\n        n_rows=n_rows,\n        low_memory=low_memory,\n        rechunk=False,\n        row_index=parse_row_index_args(row_index_name, row_index_offset),","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/io/ndjson.py#L307-L343","documentation":"scan_ndjson requires a positive infer_schema_length because 0 would mean sampling no rows to infer the NDJSON schema, which the engine forbids. Passing 0 is treated as an invalid argument rather than 'infer nothing'.","triggerScenarios":"pl.scan_ndjson(..., infer_schema_length=0) (also via pl.read_ndjson which forwards to scan_ndjson).","commonSituations":"Developers passing 0 intending 'skip inference' or copying a default of 0 from another library; dynamically computed schema lengths that evaluate to 0.","solutions":["Set infer_schema_length to a positive integer (e.g. 100 or the default 100)","Pass infer_schema_length=None to scan all rows for the schema","Clamp computed values: max(1, computed_length)"],"exampleFix":"// before\npl.read_ndjson('data.ndjson', infer_schema_length=0)\n// after\npl.read_ndjson('data.ndjson', infer_schema_length=None)  # or a positive int","handlingStrategy":"validation","validationCode":"if infer_schema_length is not None and infer_schema_length < 1:\n    raise ValueError('infer_schema_length must be a positive int or None')","typeGuard":null,"tryCatchPattern":"try:\n    lf = pl.scan_ndjson(path, infer_schema_length=n)\nexcept ValueError as e:\n    if 'infer_schema_length' in str(e):\n        lf = pl.scan_ndjson(path, infer_schema_length=None)","preventionTips":["Treat 0 as invalid; use None to mean 'scan everything'","Clamp dynamic values with max(1, n)","Validate config-driven schema lengths before passing"],"tags":["polars","ndjson","validation"],"backgroundTag":"value-out-of-range","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"}