pola-rs/polars · error · InvalidArgument

unsupported data type

Error message

unsupported data type: {dtype}

What it means

The data() dispatcher maps a polars dtype to a Hypothesis strategy and raises InvalidArgument for dtypes it has no branch for. Any dtype not matched by the known numeric, temporal, string, list, struct, or extension branches lands in the final else.

Solutions

  1. Use a supported dtype, or instantiate the dtype with defaults (e.g. pl.Datetime('us')).
  2. Check the dtype against polars' supported list for parametric strategies before calling data().
  3. If this is a newly added polars dtype, update strategies/data.py to add a branch for it.

Example fix

// before
data(dtype=pl.Unknown)
// after
data(dtype=pl.String)
Defensive patterns

Strategy: try-catch

Validate before calling

SUPPORTED = (pl.Int8, pl.Int16, pl.Int32, pl.Int64, pl.UInt8, pl.UInt16, pl.UInt32, pl.UInt64, pl.Float32, pl.Float64, pl.String, pl.Boolean, pl.Date, pl.Datetime, pl.Duration, pl.Time, pl.List, pl.Struct)
if not any(dtype == d for d in SUPPORTED):
    raise ValueError(f"dtype {dtype} not supported by parametric strategies")

Type guard

def is_strategy_supported(dtype: pl.DataType) -> bool:
    try:
        data(dtype)
        return True
    except Exception:
        return False

Try / catch

from polars.exceptions import InvalidArgument
try:
    strategy = data(dtype)
except InvalidArgument as e:
    pytest.skip(f"no strategy for {dtype}: {e}")

Prevention

When it happens

Trigger: Calling data(dtype) with an unsupported dtype such as pl.Map variants not handled, Categorical variants, or a custom/unregistered DataType; passing a DataTypeClass instead of an instantiated dtype when required.

Common situations: Adding a new polars dtype that the testing strategies module has not been updated for; passing exotic dtypes (BinaryOffset, Unknown) into parametric strategies; plugin/extension dtypes from pyo3-polars.

Related errors


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

Appendix: source

Thrown at py-polars/src/polars/testing/parametric/strategies/data.py:522

        strategy = lists(
            inner,
            min_size=size,
            max_size=size,
            allow_null=allow_null,
            **kwargs,
        )
    elif dtype == Map:
        key = getattr(dtype, "key", None) or Null()
        value = getattr(dtype, "value", None) or Null()
        strategy = maps(key, value, allow_null=allow_null, **kwargs)
    elif dtype == Struct:
        fields = getattr(dtype, "fields", None) or [Field("f0", Null())]
        strategy = structs(fields, allow_null=allow_null, **kwargs)
    elif isinstance(dtype, BaseExtension):
        strategy = data(dtype.ext_storage(), allow_null=allow_null, **kwargs)
    else:
        msg = f"unsupported data type: {dtype}"
        raise InvalidArgument(msg)

    if allow_null:
        strategy = nulls() | strategy

    return strategy

View on GitHub (pinned to fe841f959e)