macrosynergy.download.extra#

save_data(path, data)[source]#

Save data locally, choosing the file format based on the data type.

DataFrames are saved as Parquet, dicts and lists as JSON, and all other objects as pickle. The extension in “path” is replaced with the appropriate suffix regardless of what was originally supplied.

Parameters:
  • path (str or Path) – Destination path. The extension is overridden based on the data type.

  • data (Any) – Object to persist. Its type determines the output format.

Returns:

Path of the file that was written, with the correct extension applied: “.parquet” for DataFrames, “.json” for dicts and lists, and “.pkl” for everything else.

Return type:

Path

load_data(path)[source]#

Load data previously saved by “save_data”, inferring the format from the file extension.

If “path” has no extension, the function probes for “.parquet”, “.json”, and “.pkl” files in that order and loads the first match found.

Parameters:

path (str or Path) – Path to the saved file. The extension may be omitted if the file was written by “save_data”.

Returns:

The deserialized data: a DataFrame for “.parquet” files, a dict or list for “.json” files, and the original pickled object for “.pkl” files.

Return type:

Any