{"record":{"id":"6034696e4a8de8ed","repo":"pola-rs/polars","slug":"given-n-dtypes-dtypes-for-n-cols-names","errorCode":null,"errorMessage":"given {n_dtypes} dtypes for {n_cols} names","messagePattern":"given (.+?) dtypes for (.+?) names","errorType":"validation","errorClass":"InvalidArgument","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/testing/parametric/strategies/legacy.py","lineNumber":102,"sourceCode":"    ...     assert_something(df)\n    \"\"\"\n    # create/assign named columns\n    if cols is None:\n        cols = st.integers(min_value=min_cols, max_value=max_cols).example()\n    if isinstance(cols, int):\n        names: Sequence[str] = [f\"col{n}\" for n in range(cols)]\n    else:\n        names = cols\n    n_cols = len(names)\n\n    if dtype is None:\n        dtypes: Sequence[PolarsDataType | None] = [None] * n_cols\n    elif is_polars_dtype(dtype):\n        dtypes = [dtype] * n_cols\n    elif isinstance(dtype, Sequence):\n        if (n_dtypes := len(dtype)) != n_cols:\n            msg = f\"given {n_dtypes} dtypes for {n_cols} names\"\n            raise InvalidArgument(msg)\n        dtypes = dtype\n    else:\n        msg = f\"{dtype!r} is not a valid polars datatype\"\n        raise InvalidArgument(msg)\n\n    # init list of named/typed columns\n    return [\n        column(name=nm, dtype=tp, unique=unique)\n        for nm, tp in zip(names, dtypes, strict=True)\n    ]\n\n\n@deprecated(\"`create_list_strategy` is deprecated; use `lists` instead.\")\ndef create_list_strategy(\n    inner_dtype: PolarsDataType | None = None,\n    *,\n    select_from: Sequence[Any] | None = None,\n    size: int | None = None,","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/pola-rs/polars/blob/9b5d73fd00236295624374b075d16b1fe6ec6df9/py-polars/src/polars/testing/parametric/strategies/legacy.py#L84-L120","documentation":"Validation in the legacy `dataframes` strategy: when dtype is passed as a sequence, its length must equal the number of generated column names (cols). A mismatch means dtypes cannot be paired with columns one-to-one. Supply one dtype per column or a single dtype.","triggerScenarios":"Thrown at py-polars/src/polars/testing/parametric/strategies/legacy.py:102 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass the same number of dtypes as column names (or omit dtypes to let them be inferred)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"9b5d73fd00236295624374b075d16b1fe6ec6df9","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}