write_resource_batch

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 🚧

write_resource_batch(
    data: pl.DataFrame,
    resource_properties: ResourceProperties,
    package_path: Path | None = None,
)

Write the tidied data into the resource’s batch data folder.

Use this function to write the original data that is in a tidy Polars DataFrame to the resource folder provided by the path property in the resource_properties. The function saves the DataFrame as file with a timestamped, unique name, as a backup. See the design docs for an explanation of this batch file. Data is always checked against the resource_properties before it is written to the batch folder.

Parameters

data : pl.DataFrame

A Polars DataFrame object with the data to write to the batch folder.

resource_properties : ResourceProperties

The properties object for the specific resource. Use read_properties() to read the properties for the resource.

package_path : Path | None = None

The path to the data package root folder (where datapackage.json is located). Defaults to the current working directory.

Returns

Path

The path to the written Parquet resource file.

Raises

ExceptionGroup[CheckError]

If the resource properties are incorrect.

ValueError

If column names in the data are incorrect.

ExceptionGroup[ValueError]

If data types in the data are incorrect.

Examples

import seedcase_sprout as sp

with sp.ExamplePackage():
    resource_properties = sp.read_properties().resources[0]
    sp.write_resource_batch(
        data=sp.example_data(),
        resource_properties=resource_properties,
    )
PosixPath('/tmp/tmpbmx02dnu/example-package/resources/example-resource/batch/2025-06-26T013020Z-8af571f5-5c34-43f8-84fb-155681dd9be9.parquet')