nwm_region_mgr.utils.io_utils.save_data#
- nwm_region_mgr.utils.io_utils.save_data(data, file_path, index=False)[source]#
Save data to disk in an appropriate format based on its type and file extension.
- Return type:
None- Parameters:
data –
Union[pandas.DataFrame, pydantic.BaseModel] The data object to save. Must be either a pandas DataFrame or a Pydantic BaseModel.
- If data is a pandas DataFrame:
Supported file formats: .csv, .parquet.
- If data is a Pydantic BaseModel:
Supported file format: .yaml.
file_path – Union[str, pathlib.Path] The target file path where the data will be saved. The file extension determines the format.
index – bool Whether to write row indices in the DataFrame (default: False).
- Raises:
Exception – If the file extension is not supported for the given data type.
ValueError – If data is neither a pandas DataFrame nor a Pydantic BaseModel.
Notes
If the directory for the specified file path does not exist, it will be created.
YAML files for Pydantic models are written with custom inline list formatting (if configured).