dataframely.experimental.infer_schema#

dataframely.experimental.infer_schema(df: DataFrame, schema_name: str = 'Schema') str[source]#

Infer a dataframely schema from a Polars DataFrame.

This function inspects a DataFrame’s schema and generates corresponding dataframely Schema code as a string.

Parameters:
  • df – The Polars DataFrame to infer the schema from.

  • schema_name – The name for the generated schema class.

Returns:

The schema code as a string.

Example

>>> import polars as pl
>>> from dataframely.experimental import infer_schema
>>> df = pl.DataFrame({
...     "name": ["Alice", "Bob"],
...     "age": [25, 30],
...     "score": [95.5, None],
... })
>>> print(infer_schema(df, "PersonSchema"))
class PersonSchema(dy.Schema):
    name = dy.String()
    age = dy.Int64()
    score = dy.Float64(nullable=True)

Attention

This functionality is considered unstable. It may be changed at any time without it being considered a breaking change.

Raises:

ValueError – If schema_name is not a valid Python identifier.