{"record":{"id":"14b8b173fd35dfd3","repo":"reflex-dev/reflex","slug":"cannot-pass-in-both-a-pandas-dataframe-and-columns-14b8b1","errorCode":null,"errorMessage":"Cannot pass in both a pandas dataframe and columns to the data_table component.","messagePattern":"Cannot pass in both a pandas dataframe and columns to the data_table component\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"packages/reflex-components-gridjs/src/reflex_components_gridjs/datatable.py","lineNumber":84,"sourceCode":"        if is_computed_var(data) and data._var_type == Any:\n            msg = \"Annotation of the computed var assigned to the data field should be provided.\"\n            raise ValueError(msg)\n\n        if (\n            columns is not None\n            and is_computed_var(columns)\n            and columns._var_type == Any\n        ):\n            msg = \"Annotation of the computed var assigned to the column field should be provided.\"\n            raise ValueError(msg)\n\n        # If data is a pandas dataframe and columns are provided throw an error.\n        if (\n            types.is_dataframe(type(data))\n            or (isinstance(data, Var) and types.is_dataframe(data._var_type))\n        ) and columns is not None:\n            msg = \"Cannot pass in both a pandas dataframe and columns to the data_table component.\"\n            raise ValueError(msg)\n\n        # If data is a list and columns are not provided, throw an error\n        if (\n            (isinstance(data, Var) and types.typehint_issubclass(data._var_type, list))\n            or isinstance(data, list)\n        ) and columns is None:\n            msg = \"column field should be specified when the data field is a list type\"\n            raise ValueError(msg)\n\n        # Create the component.\n        return super().create(\n            *children,\n            **props,\n        )\n\n    def add_imports(self) -> ImportDict:\n        \"\"\"Add the imports for the datatable component.\n","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-components-gridjs/src/reflex_components_gridjs/datatable.py#L66-L102","documentation":"data_table auto-derives columns from a pandas DataFrame; passing columns together with a DataFrame is ambiguous and rejected.","triggerScenarios":"rx.data_table(data=df, columns=[...]) where data is a pd.DataFrame or a Var whose _var_type is a DataFrame.","commonSituations":"Wanting custom column labels while passing the raw DataFrame instead of pre-selecting/renaming columns in pandas.","solutions":["Remove the columns prop and let the DataFrame define them","Or pre-shape the DataFrame (select/rename) before passing","Or convert data to a list of rows and pass columns explicitly"],"exampleFix":"# before\nrx.data_table(data=df, columns=[\"a\", \"b\"])\n# after\nrx.data_table(data=df[[\"a\", \"b\"]])","handlingStrategy":"validation","validationCode":"import pandas as pd\nif isinstance(data, pd.DataFrame) and columns is not None:\n    data = data[[c for c in columns]] if all(isinstance(c, str) for c in columns) else data\n    columns = None","typeGuard":"def df_plus_columns(data: Any, columns: Any) -> bool:\n    import pandas as pd\n    return isinstance(data, pd.DataFrame) and columns is not None","tryCatchPattern":null,"preventionTips":["Never pass columns with a DataFrame to data_table","Pre-shape DataFrames with df[...] / .rename()"],"tags":["reflex","gridjs","dataframe"],"backgroundTag":"conflicting-arguments","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}