{"record":{"id":"e16133b3af8bd1fd","repo":"pola-rs/polars","slug":"expected-data-of-type-sequence-got-type-data-name-r-n-nhint","errorCode":null,"errorMessage":"expected data of type Sequence, got {type(data).__name__!r}\\n\\nHint: Try passing your data to the DataFrame constructor instead, e.g. `pl.DataFrame(data)`.","messagePattern":"expected data of type Sequence, got (.+?)\\\\n\\\\nHint: Try passing your data to the DataFrame constructor instead, e\\.g\\. `pl\\.DataFrame\\(data\\)`\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/convert/general.py","lineNumber":297,"sourceCode":"    >>> df\n    shape: (3, 2)\n    ┌─────┬─────┐\n    │ a   ┆ b   │\n    │ --- ┆ --- │\n    │ i64 ┆ i64 │\n    ╞═════╪═════╡\n    │ 1   ┆ 4   │\n    │ 2   ┆ 5   │\n    │ 3   ┆ 6   │\n    └─────┴─────┘\n    \"\"\"\n    if not isinstance(data, Sequence):\n        msg = (\n            f\"expected data of type Sequence, got {type(data).__name__!r}\"\n            \"\\n\\nHint: Try passing your data to the DataFrame constructor instead,\"\n            \" e.g. `pl.DataFrame(data)`.\"\n        )\n        raise TypeError(msg)\n\n    return wrap_df(\n        sequence_to_pydf(\n            data,\n            schema=schema,\n            schema_overrides=schema_overrides,\n            strict=strict,\n            orient=orient,\n            infer_schema_length=infer_schema_length,\n        )\n    )\n\n\ndef from_numpy(\n    data: np.ndarray[Any, Any],\n    schema: SchemaDefinition | None = None,\n    *,\n    schema_overrides: SchemaDict | None = None,","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/convert/general.py#L279-L315","documentation":"pl.from_records requires data to be an instance of collections.abc.Sequence (list, tuple, etc.). Passing a non-sequence such as a dict, set, generator, or numpy array that doesn't qualify raises a TypeError with a hint to use the DataFrame constructor instead.","triggerScenarios":"pl.from_records({'a': [1,2]}), pl.from_records(some_set), pl.from_records(some_generator), or passing a dict-of-columns that should go through pl.DataFrame.","commonSituations":"Confusing from_records (rows as sequences) with from_dict (columns by name); passing generators or sets that were assumed to be 'record-like'; numpy arrays routed to the wrong constructor.","solutions":["Use pl.DataFrame(data) or pl.from_dict(data) for dict-of-columns input.","Convert to a list first: pl.from_records(list(data)).","For generators: pl.from_records(list(gen)) or pl.DataFrame(gen).","For numpy arrays, use pl.DataFrame(arr) or pass arr.tolist()."],"exampleFix":"// before\npl.from_records({\"a\": [1, 2], \"b\": [3, 4]})\n// after\npl.from_dict({\"a\": [1, 2], \"b\": [3, 4]})","handlingStrategy":"type-guard","validationCode":"from collections.abc import Sequence\nif not isinstance(data, Sequence):\n    raise TypeError(\"from_records needs a Sequence; use pl.DataFrame/pl.from_dict for other shapes\")\npl.from_records(data)","typeGuard":"from collections.abc import Sequence, Mapping\ndef is_record_sequence(v) -> bool:\n    return isinstance(v, Sequence) and not isinstance(v, (str, bytes, Mapping))","tryCatchPattern":"try:\n    df = pl.from_records(data)\nexcept TypeError:\n    df = pl.DataFrame(data)  # handles dicts, arrays, generators","preventionTips":["Use from_dict for column-mapping dicts and from_records for row sequences.","Materialize generators/sets with list() before calling.","When unsure, pl.DataFrame(data) accepts the widest range of inputs."],"tags":["python","polars","type-error","wrong-constructor"],"backgroundTag":"type-mismatch","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"}