{"record":{"id":"8a97f2324185807c","repo":"pola-rs/polars","slug":"invalid-return-type-found-return-type-r-expe","errorCode":null,"errorMessage":"invalid `return_type`; found {return_type!r}, expected one of 'string', 'frame', 'self', or None","messagePattern":"invalid `return_type`; found (.+?), expected one of 'string', 'frame', 'self', or None","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/dataframe/frame.py","lineNumber":5859,"sourceCode":"        ┌─────┬──────┬───────┬──────┬──────┬────────────┐\n        │ a   ┆ b    ┆ c     ┆ d    ┆ e    ┆ f          │\n        │ --- ┆ ---  ┆ ---   ┆ ---  ┆ ---  ┆ ---        │\n        │ f64 ┆ i64  ┆ bool  ┆ str  ┆ str  ┆ date       │\n        ╞═════╪══════╪═══════╪══════╪══════╪════════════╡\n        │ 1.0 ┆ 4    ┆ true  ┆ null ┆ usd  ┆ 2020-01-01 │\n        │ 2.8 ┆ 5    ┆ false ┆ b    ┆ eur  ┆ 2021-01-02 │\n        │ 3.0 ┆ null ┆ true  ┆ c    ┆ null ┆ 2022-01-01 │\n        └─────┴──────┴───────┴──────┴──────┴────────────┘\n        \"\"\"  # noqa: W505\n        # handle boolean value from now-deprecated `return_as_string` parameter\n        if isinstance(return_type, bool) or return_type is None:  # type: ignore[redundant-expr]\n            return_type = \"string\" if return_type else None  # type: ignore[redundant-expr]\n            return_frame = False\n        else:\n            return_frame = return_type == \"frame\"\n            if not return_frame and return_type not in (\"self\", \"string\"):\n                msg = f\"invalid `return_type`; found {return_type!r}, expected one of 'string', 'frame', 'self', or None\"\n                raise ValueError(msg)\n\n        # always print at most this number of values (mainly ensures that\n        # we do not cast long arrays to strings, which would be slow)\n        max_n_values = min(max_items_per_column, self.height)\n        schema = self.schema\n\n        def _column_to_row_output(\n            col_name: str, dtype: PolarsDataType\n        ) -> tuple[str, str, list[str | None]]:\n            fn = repr if schema[col_name] == String else str\n            values = self[:max_n_values, col_name].to_list()\n            if len(col_name) > max_colname_length:\n                col_name = col_name[: (max_colname_length - 1)] + \"…\"\n            dtype_str = _dtype_str_repr(dtype)\n            if not return_frame:\n                dtype_str = f\"<{dtype_str}>\"\n            return (\n                col_name,","sourceCodeStart":5841,"sourceCodeEnd":5877,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/dataframe/frame.py#L5841-L5877","documentation":"Raised by DataFrame.glimpse when its `return_type` parameter is not a recognized value. `return_type` controls the return format: None prints the preview to stdout, 'self' prints and returns the original frame, 'frame' returns the preview as a new DataFrame, and 'string' returns the preview text. Booleans are still accepted silently for backwards compatibility with the deprecated `return_as_string` parameter (True -> 'string', False -> None), so only other values reach this ValueError.","triggerScenarios":"Calling df.glimpse(return_type=...) with a value like 'str', 'text', 'Frame', 'df', an int, or any string that does not exactly match 'string'/'frame'/'self' (case-sensitive), e.g. df.glimpse(return_type='str').","commonSituations":"Upgrading polars to >=1.35.0 where return_as_string was renamed return_type; guessing the new literal when migrating; passing the value from a config variable or CLI flag with a typo; dynamic preview wrappers that forward user input unvalidated.","solutions":["Set return_type to exactly one of 'string', 'frame', 'self', or omit it (None) for print-only behavior","If migrating from the old API: return_as_string=True -> return_type='string', return_as_string=False -> return_type=None (passing the raw bool also still works)","Validate/normalize config-driven values against {'string','frame','self',None} before calling glimpse","Check case and spelling — the comparison is exact"],"exampleFix":"# before\ntext = df.glimpse(return_type='str')\n\n# after\ntext = df.glimpse(return_type='string')","handlingStrategy":"validation","validationCode":"VALID = {'string', 'frame', 'self', None}\nreturn_type = return_type if return_type in VALID else 'string'  # or raise your own config error\ndf.glimpse(return_type=return_type)","typeGuard":"def is_glimpse_return_type(v: object) -> bool:\n    return v is None or (isinstance(v, str) and v in {'string', 'frame', 'self'})","tryCatchPattern":null,"preventionTips":["Centralize the literal in one constant (e.g. GLIMPSE_RETURN = 'string') instead of retyping it at call sites","When migrating from return_as_string, map True->'string', False->None explicitly in one place","Validate config/CLI-sourced values against {'string','frame','self',None} before forwarding them"],"tags":["polars","dataframe","glimpse","parameter-validation","valueerror","api-migration"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}