stemflow.lazyloading.data_preparation
Helpers for preparing model-ready DuckDB input from numeric Pandas DataFrames. See parallel execution and memory for workflow examples and cleanup behavior.
Create model-ready DuckDB inputs from familiar Pandas objects.
make_duckdb_database(frame, path, *, memory_limit='500MB', overwrite=False)
Save a numeric DataFrame as one model-ready DuckDB table.
Observation IDs come from frame.index and row order is retained.
No SQL knowledge, manual ID column, or SQL index creation is needed.
Returns an absolute filename suitable for split/predict.
Existing files are protected unless overwrite=True.
The caller's DataFrame is not modified or freed.
Source code in stemflow/lazyloading/data_preparation.py
make_training_databases(X, y, directory, *, memory_limit='500MB', overwrite=False)
Create paired X/y DuckDB files and return (X_path, y_path).
Pandas labels align by observation ID, including shuffled labels.
NumPy/list labels align by position. Both database files contain one
tmp table and the ID column required by AdaSTEM. They are closed
before returning, so parallel workers can open them read-only.
Use training_databases for automatic temporary-file cleanup.
Source code in stemflow/lazyloading/data_preparation.py
training_databases(X, y, *, directory=None, memory_limit='500MB')
Yield temporary (X_path, y_path) and clean up on success/failure.
directory optionally selects node-local scratch, such as
os.environ.get('SLURM_TMPDIR'). Each context gets its own folder.
Keep the context open until fit and other input reads complete.