import ogcore.output_tables as ot
from io import BytesIO
import pickle
import requests
path_dict = {
"TPI": [
"https://github.com/PSLmodels/OG-Core/blob/master/tests/test_io_data/TPI_vars_baseline.pkl?raw=true",
"https://github.com/PSLmodels/OG-Core/blob/master/tests/test_io_data/TPI_vars_reform.pkl?raw=true"
],
"Params": [
"https://github.com/PSLmodels/OG-Core/blob/master/tests/test_io_data/model_params_baseline.pkl?raw=true",
"https://github.com/PSLmodels/OG-Core/blob/master/tests/test_io_data/model_params_reform.pkl?raw=true"
]
}
output_dict = {
"TPI": [],
"Params": []
}
for key in path_dict.keys():
for path in path_dict[key]:
r = requests.get(path)
output_dict[key].append(pickle.load(BytesIO(r.content)))
# make table
table = ot.macro_table(output_dict["TPI"][0], output_dict["Params"][0], output_dict["TPI"][1], output_dict["Params"][1], output_type="pct_diff", num_years=10, start_year= output_dict["Params"][0].start_year)
I have no issue executing this in Python 3.10. But with Python 3.11, there is an error with the pickle.load
command when trying to read the pickle file containing the model parameters (which is a ogcore.parameters.Specifications
object pickled with Cloudpickle). The traceback is:
TypeError Traceback (most recent call last)
Cell In[2], line 24
22 for path in path_dict[key]:
23 r = requests.get(path)
---> 24 output_dict[key].append(pickle.load(BytesIO(r.content)))
25 # make table
26 table = ot.macro_table(output_dict["TPI"][0], output_dict["Params"][0], output_dict["TPI"][1], output_dict["Params"][1], output_type="pct_diff", num_years=10, start_year= output_dict["Params"][0].start_year)
TypeError: code() argument 13 must be str, not int