extract_resource_properties

Warning

🚧 Sprout is still in active development and evolving quickly, so the documentation and functionality may not work as described and could undergo substantial changes 🚧

extract_resource_properties(data: pl.DataFrame)

Extracts resource properties from Polars DataFrame.

The data types are extracted from the DataFrame’s schema and mapped from Polars to Data Package data types. For the best results, ensure the DataFrame’s schema is as expected. Since there are differences between Polars and Data Package data types, the mapping may not always be perfect, and some data types might be extracted in a simplified way. For example, a year column might be extracted as an integer instead of Data Package’s year type. Review and adjust the extracted properties as needed.

Parameters

data : pl.DataFrame

A Polars DataFrame containing the data to extract properties from.

Returns

ResourceProperties

A ResourceProperties object.

Raises

ValueError

If the data is empty

Examples

import seedcase_sprout as sp

sp.extract_resource_properties(
    data=sp.example_data(),
)
ResourceProperties(name=None, path=None, type='table', title=None, description=None, sources=None, licenses=None, format=None, mediatype=None, encoding=None, bytes=None, hash=None, schema=TableSchemaProperties(fields=[FieldProperties(name='id', title=None, type='integer', format=None, description=None, example=None, constraints=None, categories=None, categories_ordered=None, missing_values=None), FieldProperties(name='name', title=None, type='string', format=None, description=None, example=None, constraints=None, categories=None, categories_ordered=None, missing_values=None), FieldProperties(name='value', title=None, type='number', format=None, description=None, example=None, constraints=None, categories=None, categories_ordered=None, missing_values=None)], fields_match='equal', primary_key=None, unique_keys=None, foreign_keys=None, missing_values=None))