extract_field_properties

extract_field_properties(data: pl.DataFrame)

Extract field properties from a Polars DataFrame.

Data types are extracted from the DataFrame’s schema and mapped from Polars to Data Package data types. For the best results, ensure that the DataFrame’s schema is correct—this may require some manually fixing. Since there are differences between Polars and Data Package data types, the mapping may not always be perfect, and some data types may be extracted to simpler types. For example, a year column may be extracted as an integer instead of Data Package’s year type. Be sure to review and modify the extracted properties to suit your needs.

Parameters

data : pl.DataFrame

A Polars DataFrame containing the data to extract properties from.

Returns

list[FieldProperties]

A list of FieldProperties objects, each representing a field/column in the

list[FieldProperties]

DataFrame.

Raises

ValueError

If the data is empty.

Examples

import seedcase_sprout as sp

sp.extract_field_properties(
    data=sp.example_data(),
)
[FieldProperties(name='id', title=None, type='integer', format=None, description=None, example=None, constraints=None, categories=None, categories_ordered=None),
 FieldProperties(name='name', title=None, type='string', format=None, description=None, example=None, constraints=None, categories=None, categories_ordered=None),
 FieldProperties(name='value', title=None, type='number', format=None, description=None, example=None, constraints=None, categories=None, categories_ordered=None)]