streamlit / streamlit

Streamlit — A faster way to build and share data apps.
https://streamlit.io
Apache License 2.0
37.43k stars 3.23k forks source link

Support Polars objects for cache hashing #10347

Open BartSchuurmans opened 1 week ago

BartSchuurmans commented 1 week ago

Checklist

Summary

When passing a Polars dataframe to a function that is decorated with @st.cache_data, you get the following error:

UnhashableParamError: Cannot hash argument 'my_df' (of type polars.dataframe.frame.DataFrame) in 'my_func'.

Follow-up of https://github.com/streamlit/streamlit/issues/5088#issuecomment-2338389918

Why?

I want to be able to cache functions that have a Polars dataframe as input.

How?

There is already support for Pandas dataframes:

https://github.com/streamlit/streamlit/blob/9914751b0d59f55cb03c3e871e90f65264895431/lib/streamlit/runtime/caching/hashing.py#L434-L453

Support for Polars dataframes could be implemented the same way. Alternative: Use https://github.com/narwhals-dev/narwhals for a dataframe-agnostic implementation.

Additional Context

No response

github-actions[bot] commented 1 week ago

To help Streamlit prioritize this feature, react with a 👍 (thumbs up emoji) to the initial post.

Your vote helps us identify which enhancements matter most to our users.

Visits

MarcoGorelli commented 1 week ago

Hey

Alternative: Use https://github.com/narwhals-dev/narwhals for a dataframe-agnostic implementation.

I just wanted to note that Streamlit depends on Altair, which in turn already depends on Narwhals. So, Streamlit would be able to use Narwhals functionality with zero cost to its users as they all already have it installed because of Altair