@st.cache was deprecated in Streamlit 1.18.0. So st.cache will never support caching Polars dataframes. We recommend using one of the new caching email@example.com_data as a replacement to cache data.
Here’s an example demonstrating caching of a Polars dataframe:
@Fabio I’m guessing you’re running into the UnhashableParamError when passing a Polars dataframe as an argument to a cache-decorated function. To tell Streamlit to stop hashing the argument, add a leading underscore to the argument’s name in the function signature:
On taking another look, I realize you’re correct in thinking that the function will not rerun if the excluded parameter (when it is the only param to the function) doesn’t change.
What you can do in this case is pass another input param to the cached function that changes whenever the polars dataframe changes. One such option is to use polars.DataFrame.hash_rows in conjunction with polars.Series.view. The first method hashes and combines the rows in the polars DataFrame. As the result is an unhashable polars.Series object, we convert it to a NumPy array containing the UInt64 hashes: