Coverage for src / prepare_times_nz / utilities / data_in_out.py: 43%

7 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-01 22:14 +0000

1""" 

2Standardised helper functions for saving/loading data 

3 

4Could wrap this in more comprehensive logging if we wanted! 

5 

6Long term, ideally every in/out would be wrapped in here 

7and the script's inputs and outputs can be logged 

8This will help us trace how things flow through later. 

9For now, just standard helpers to be used elsewhere 

10""" 

11 

12from pathlib import Path 

13 

14from prepare_times_nz.utilities.logger_setup import blue_text, logger 

15 

16 

17def _save_data(df, name, label, filepath: Path): 

18 """Save DataFrame output to the output location and print to console""" 

19 filepath.mkdir(parents=True, exist_ok=True) 

20 filename = filepath / name 

21 logger.info("%s: %s", label, blue_text(filename)) 

22 df.to_csv(filename, index=False, encoding="utf-8-sig")