reflex-dev/reflex · error · ValueError

Cannot pass in both a pandas dataframe and columns to the da

Error message

Cannot pass in both a pandas dataframe and columns to the data_table component.

What it means

data_table auto-derives columns from a pandas DataFrame; passing columns together with a DataFrame is ambiguous and rejected.

Source

Thrown at packages/reflex-components-gridjs/src/reflex_components_gridjs/datatable.py:84

        if is_computed_var(data) and data._var_type == Any:
            msg = "Annotation of the computed var assigned to the data field should be provided."
            raise ValueError(msg)

        if (
            columns is not None
            and is_computed_var(columns)
            and columns._var_type == Any
        ):
            msg = "Annotation of the computed var assigned to the column field should be provided."
            raise ValueError(msg)

        # If data is a pandas dataframe and columns are provided throw an error.
        if (
            types.is_dataframe(type(data))
            or (isinstance(data, Var) and types.is_dataframe(data._var_type))
        ) and columns is not None:
            msg = "Cannot pass in both a pandas dataframe and columns to the data_table component."
            raise ValueError(msg)

        # If data is a list and columns are not provided, throw an error
        if (
            (isinstance(data, Var) and types.typehint_issubclass(data._var_type, list))
            or isinstance(data, list)
        ) and columns is None:
            msg = "column field should be specified when the data field is a list type"
            raise ValueError(msg)

        # Create the component.
        return super().create(
            *children,
            **props,
        )

    def add_imports(self) -> ImportDict:
        """Add the imports for the datatable component.

View on GitHub (pinned to 45b8ed5ab7)

Solutions

  1. Remove the columns prop and let the DataFrame define them
  2. Or pre-shape the DataFrame (select/rename) before passing
  3. Or convert data to a list of rows and pass columns explicitly

Example fix

# before
rx.data_table(data=df, columns=["a", "b"])
# after
rx.data_table(data=df[["a", "b"]])
Defensive patterns

Strategy: validation

Validate before calling

import pandas as pd
if isinstance(data, pd.DataFrame) and columns is not None:
    data = data[[c for c in columns]] if all(isinstance(c, str) for c in columns) else data
    columns = None

Type guard

def df_plus_columns(data: Any, columns: Any) -> bool:
    import pandas as pd
    return isinstance(data, pd.DataFrame) and columns is not None

Prevention

When it happens

Trigger: rx.data_table(data=df, columns=[...]) where data is a pd.DataFrame or a Var whose _var_type is a DataFrame.

Common situations: Wanting custom column labels while passing the raw DataFrame instead of pre-selecting/renaming columns in pandas.

Related errors


AI-assisted analysis of reflex-dev/reflex@45b8ed5ab7 (2026-08-28). Data as JSON: /api/errors/14b8b173fd35dfd3. Report an issue: GitHub.