file_io#

Functions

append_to_jsonl(f, data)

Append data to a jsonl file.

load([f])

Load both the json and pickle files and return the object from the json file

load_json([f])

Load the object from a json file.

load_jsonl([f])

Load a jsonl file and return a list of dictionaries.

load_pickle([f])

Load the object from a pickle file.

save(obj[, f])

Save the object to both a json and a pickle file.

save_csv(obj[, f, fieldnames])

Save the object to a csv file.

save_json(obj[, f])

Save the object to a json file.

save_pickle(obj[, f])

Save the object to a pickle file.

write_list_to_jsonl(f, data)

Write a list of dictionaries to a jsonl file.

save_json(obj: Mapping[str, Any], f: str = 'task.json') None[source]#

Save the object to a json file.

Parameters:
  • obj (Mapping[str, Any]) – The object to be saved.

  • f (str, optional) – The file name. Defaults to “task”.

save_csv(obj: List[Dict[str, Any]], f: str = 'task.csv', fieldnames: List[str] = None) None[source]#

Save the object to a csv file.

Parameters:
  • obj (List[Dict[str, Any]]) – The object to be saved.

  • f (str, optional) – The file name. Defaults to “task”.

save_pickle(obj: Mapping[str, Any], f: str = 'task.pickle') None[source]#

Save the object to a pickle file.

Parameters:
  • obj (Mapping[str, Any]) – The object to be saved.

  • f (str, optional) – The file name. Defaults to “task”.

save(obj: Mapping[str, Any], f: str = 'task') None[source]#

Save the object to both a json and a pickle file.

We save two versions of the object: - task.json: the object itself with Parameter serialized to dict - task.pickle: the object itself with Parameter as is

load_json(f: str = 'task.json') Mapping[str, Any] | None[source]#

Load the object from a json file.

Parameters:

f (str, optional) – The file name. Defaults to “task”.

load_pickle(f: str = 'task.pickle') Mapping[str, Any] | None[source]#

Load the object from a pickle file.

Parameters:

f (str, optional) – The file name. Defaults to “task”.

load(f: str = 'task') Mapping[str, Any] | None[source]#

Load both the json and pickle files and return the object from the json file

Parameters:

f (str, optional) – The file name. Defaults to “task”.

load_jsonl(f: str = None) List[Dict[str, Any]][source]#

Load a jsonl file and return a list of dictionaries.

Parameters:

f (str, optional) – The file name. Defaults to None.

append_to_jsonl(f: str, data: Dict[str, Any]) None[source]#

Append data to a jsonl file.

Used by the trace_generator_call decorator to log the generator calls.

Parameters:
  • f (str) – The file name.

  • data (Dict[str, Any]) – The data to be appended.

write_list_to_jsonl(f: str, data: List[Dict[str, Any]]) None[source]#

Write a list of dictionaries to a jsonl file.

Parameters:
  • f (str) – The file name.

  • data (List[Dict[str, Any]]) – The data to be written.