St.cache and ouput mutation

Hi all,

I have decorated with st.cache a function which brings data from a dataframe, in order to speed up refreshes etc…

Once this dataframe is exported the following steps are taken.

  1. this dataframe is displayed in my streamlit app.
  2. once a button is clicked this dataframe is fed into another decorated function that implements computations on it.
  3. outputs the computation results in a new dataframe which is the old one with some columns added

Q:
Inevitably I have to allow output mutation, but the problem I face is that in step (1) i get as an output the same dataframe as in (3). What can I do in order to always display the initial version of the dataframe?

*although once the values are return from the dataframe I implement df.copy() and I always display the copy in step(1) I get a mutated output. Any ideas?

Thank you

Sounds like pandas is trying to do you a favor in re-using memory that you don’t want :laughing:

I wonder if a deep copy is what you need?

1 Like

@randyzwitch Thank you.

ahha indeed! I figured out that the problem was coming from the fact that I implemented it at the wrong point.

all good now!

1 Like