I have a group of functions whose values are pandas dataframe that change over time when updating the dataframes and these functions are initially stored in a dictionary which we use when needing a specific function that will return the wanted dataframe.
What I need is a way that will keep these data unchanged (fixed) across time even after the update. I tried MappingProxyType
to create an immutable dictionary but it didn't help. Here's my trial
from types import MappingProxyType
def func_x():
x = pd.DataFrame({"col1": [1,2,3], "col2": [4,5,6]})
return x
def func_y():
y = pd.DataFrame({"col3": [7,8,9], "col4": [10,20,30]})
return y
def func_z():
z = pd.DataFrame({"col5": [40,50,60], "col6": [70,80,90]})
return z
def collect_funcs_proxy(func):
collection_proxy = MappingProxyType(
{"func_x": func_x, "func_y": func_y, "func_z": func_z}
)
return collection_proxy[func]()
I mean, when changing the values of x
inside func_x
, I need collect_funcs_proxy
to keep the old values of func_x
ignoring the new update.
Is there any way I can achieve this using MappingProxyType
or something else?