pola-rs/polars · error · TypeError

dataframe contains unsupported data types

Error message

dataframe contains unsupported data types: {overlap!r}

What it means

_check_for_unsupported_types rejects DataFrames whose schema contains dtypes the deltalake writer cannot round-trip (currently Time and Null). polars raises TypeError listing the offending dtype overlap.

Solutions

  1. Cast pl.Time columns to pl.String (or Duration) before writing
  2. Cast pl.Null columns to a concrete type (e.g. pl.Int32) or drop them
  3. Update polars/deltalake, as the unsupported set may shrink in newer versions

Example fix

// before
pl.write_delta(df, uri)  # df has a pl.Time column
// after
df = df.with_columns(pl.col('event_time').cast(pl.String))
pl.write_delta(df, uri)
Defensive patterns

Strategy: validation

Validate before calling

bad = {pl.Time, pl.Null}
if set(df.schema.dtypes()) & bad:
    df = df.with_columns(
        pl.col(c).cast(pl.String) for c, t in df.schema.items() if t == pl.Time
    ).drop([c for c, t in df.schema.items() if t == pl.Null])

Try / catch

try:
    pl.write_delta(df, uri)
except TypeError as e:
    if 'unsupported data types' in str(e):
        df = sanitize_dtypes(df)
        pl.write_delta(df, uri)

Prevention

When it happens

Trigger: pl.write_delta(df, ...) or pl.sink_delta(df, ...) where df.schema includes pl.Time or pl.Null columns.

Common situations: Writing frames parsed from time-only strings producing pl.Time, or empty/typed-null columns from joins or select of literals.

Related errors


AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18). Data as JSON: /api/errors/68656507e37536e1. Report an issue: GitHub.

Appendix: source

Thrown at py-polars/src/polars/io/delta/_utils.py:107

    return dl_tbl


def _check_if_delta_available() -> None:
    if not _DELTALAKE_AVAILABLE:
        msg = "deltalake is not installed\n\nPlease run: pip install deltalake"
        raise ModuleNotFoundError(msg)


def _check_for_unsupported_types(dtypes: list[DataType]) -> None:
    schema_dtypes = unpack_dtypes(*dtypes)
    unsupported_types = {Time, Null}
    # Note that this overlap check does NOT work correctly for Categorical, so
    # if Categorical is added back to unsupported_types a different check will
    # need to be used.

    if overlap := schema_dtypes & unsupported_types:
        msg = f"dataframe contains unsupported data types: {overlap!r}"
        raise TypeError(msg)


def _extract_table_statistics_from_delta_add_actions(
    add_actions_df: DataFrame,
    *,
    filter_columns: list[str],
    schema: SchemaDict,
    verbose: bool,
) -> DataFrame | None:
    import polars as pl

    if "num_records" not in add_actions_df:
        if verbose:
            eprint(
                "scan_delta: statistics load failed: 'num_records' column not present"
            )

        return None

View on GitHub (pinned to fe841f959e)