pola-rs/polars · error · InvalidArgument
unsupported data type
Error message
unsupported data type: {dtype} What it means
_instantiate_flat_dtype in strategies/dtype.py draws a concrete flat dtype from a DataTypeClass/selection; dtypes it cannot instantiate fall through to the final else and raise InvalidArgument. It is the flat-dtype instantiation path used by _flat_dtypes and the inner strategy machinery.
Solutions
- Restrict generated dtypes to supported flat ones via the `extra_dtypes`/`blocked_dtypes`-style selection or by passing explicit dtypes.
- Update strategies/dtype.py to handle the new dtype in _instantiate_flat_dtype.
- Ensure nested dtypes go through _instantiate_nested_dtype / _nested_dtypes, not the flat path.
Example fix
// before series(dtype=MyCustomDtype) // after series(dtype=pl.Int64)
Defensive patterns
Strategy: validation
Validate before calling
FLAT = {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.Time}
if not any(dtype == d for d in FLAT):
raise ValueError(f"{dtype} is not an instantiable flat dtype here") Type guard
def is_flat_supported(dtype) -> bool:
return not dtype.is_nested() and dtype not in (pl.Unknown,) Try / catch
from polars.exceptions import InvalidArgument
try:
dt = instantiate(dtype)
except InvalidArgument as e:
dt = pl.Int64 # fallback default for the test pool Prevention
- Restrict drawn dtypes to the supported flat pool via selection filters.
- Route nested dtypes through the nested instantiation path, not the flat one.
- Re-run hypothesis tests after polars upgrades to catch new unsupported dtypes.
When it happens
Trigger: Hypothesis drawing a dtype class that _instantiate_flat_dtype does not recognize (e.g. a nested-only or plugin dtype appearing in the flat-dtype pool); passing an unsupported dtype class into series()/instantiate helpers that route through the flat path.
Common situations: Custom or third-party dtypes used with parametric testing; polars version drift introducing a dtype not yet covered in dtype.py; accidentally requesting nested dtypes through a flat-dtype entry point.
Related errors
- map keys cannot be a nested dtype, got
- unsupported data type
- map keys cannot be Null; specify a key type, e.g…
- polars.testing.parametric requires the 'hypothesis'…
- activate dtype
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/568d47e06a3938da.
Report an issue: GitHub.
Appendix: source
Thrown at py-polars/src/polars/testing/parametric/strategies/dtype.py:272
return Datetime(time_unit, time_zone)
elif dtype == Duration:
time_unit = draw(_time_units())
return Duration(time_unit)
elif dtype == Categorical:
return Categorical()
elif dtype == Enum:
n_categories = draw(
st.integers(min_value=1, max_value=_DEFAULT_ENUM_CATEGORIES_LIMIT)
)
categories = [f"c{i}" for i in range(n_categories)]
return Enum(categories)
elif dtype == Decimal:
precision = draw(st.integers(min_value=1, max_value=38) | st.none())
scale = draw(st.integers(min_value=0, max_value=precision or 38))
return Decimal(precision, scale)
else:
msg = f"unsupported data type: {dtype}"
raise InvalidArgument(msg)
@st.composite
def _nested_dtypes(
draw: DrawFn,
inner: SearchStrategy[DataType],
allowed_dtypes: Sequence[PolarsDataType] | None = None,
excluded_dtypes: Sequence[PolarsDataType] | None = None,
*,
allow_time_zones: bool = True,
) -> DataType:
"""Create a strategy for generating nested Polars :class:`DataType` objects."""
if allowed_dtypes is None:
allowed_dtypes = _NESTED_DTYPES
if excluded_dtypes is None:
excluded_dtypes = []
dtype = draw(st.sampled_from(allowed_dtypes))View on GitHub (pinned to fe841f959e)