{"record":{"id":"927f2b46e1c196a7","repo":"pola-rs/polars","slug":"orient-must-be-one-of-col-row-none-got-orient-r","errorCode":null,"errorMessage":"`orient` must be one of {'col', 'row', None}, got {orient!r}","messagePattern":"`orient` must be one of (.+?), got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/_utils/construction/dataframe.py","lineNumber":1281,"sourceCode":"                # we check the flags to establish row/column major order\n                n_schema_cols = len(schema)\n                if n_schema_cols == shape[0] and n_schema_cols != shape[1]:\n                    orient = \"col\"\n                    n_columns = shape[0]\n                elif data.flags[\"F_CONTIGUOUS\"] and shape[0] == shape[1]:\n                    orient = \"col\"\n                    n_columns = n_schema_cols\n                else:\n                    orient = \"row\"\n                    n_columns = shape[1]\n\n            elif orient == \"row\":\n                n_columns = shape[1]\n            elif orient == \"col\":\n                n_columns = shape[0]\n            else:\n                msg = f\"`orient` must be one of {{'col', 'row', None}}, got {orient!r}\"\n                raise ValueError(msg)\n        else:\n            if shape == ():\n                msg = \"cannot create DataFrame from zero-dimensional array\"\n            else:\n                msg = f\"cannot create DataFrame from array with more than two dimensions; shape = {shape}\"\n            raise ValueError(msg)\n\n    if schema is not None and len(schema) != n_columns:\n        if (n_schema_cols := len(schema)) != 1:\n            msg = f\"dimensions of `schema` ({n_schema_cols}) must match data dimensions ({n_columns})\"\n            raise ValueError(msg)\n        n_columns = n_schema_cols\n\n    column_names, schema_overrides = _unpack_schema(\n        schema, schema_overrides=schema_overrides, n_expected=n_columns\n    )\n\n    # Convert data to series","sourceCodeStart":1263,"sourceCodeEnd":1299,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/_utils/construction/dataframe.py#L1263-L1299","documentation":"Raised by numpy_to_pydf when a 2-D numpy array is passed with an `orient` value other than 'col', 'row', or None. Orient decides whether shape[1] (row orientation) or shape[0] (column orientation) is the column count, and any other string is rejected with ValueError.","triggerScenarios":"pl.from_numpy(arr, orient='columns') or pl.DataFrame(np_arr, orient='horizontal') — non-canonical orient strings passed via from_numpy, from_torch, or __init__.","commonSituations":"Using pandas-style orient vocabulary ('index'/'columns'), typos ('cols'), config-driven orient values not normalized before the call.","solutions":["Pass orient='col', orient='row', or leave it as None","Normalize legacy values before the call, e.g. {'columns':'col','index':'row'}.get(orient)","Drop orient and reshape the array so the desired orientation is implicit (columns last)"],"exampleFix":"// before\npl.from_numpy(arr, orient='columns')\n// after\npl.from_numpy(arr, orient='col')","handlingStrategy":"validation","validationCode":"assert orient in ('col', 'row', None), f'orient must be col|row|None, got {orient!r}'","typeGuard":"def valid_orient(orient: str | None) -> bool:\n    return orient in ('col', 'row', None)","tryCatchPattern":"try:\n    df = pl.from_numpy(arr, orient=orient)\nexcept ValueError as e:\n    if 'orient' in str(e) and 'must be one of' in str(e):\n        df = pl.from_numpy(arr)  # default orientation\n    else:\n        raise","preventionTips":["Use only 'col'/'row' or None for orient","Normalize pandas-style orient strings at boundaries","For 2-D arrays, prefer the default (row-major) orientation and reshape instead of passing orient"],"tags":["python","polars","numpy","invalid-argument","orient"],"backgroundTag":"invalid-enum-value","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"}