I am using Polars dataframe
and it has date column which is getting displayed as datetime in st.write, st.dataframe, st.table
Below is a sample code just to recreate this issue:
import streamlit as st
import pandas as pd
import polars as pl
date_issue = pd.DataFrame({
"Test": ["A","B","C","D","E"],
"Date": ["1/1/2023","1/2/2023","1/3/2023","1/4/2023","1/5/2023"],
"Result": [1,2,3,4,5]
})
st.write(f"csv date type is: {date_issue['Date'].dtype}")
date_issue["Date"] = pd.to_datetime(date_issue["Date"],dayfirst=True)
st.write("After converting date type in pandas dataframe")
st.write(f"csv date type is: {date_issue['Date'].dtype}")
st.write(date_issue.dtypes)
date_issue_pl = pl.from_pandas(date_issue)
st.write("After converting pandas into polars dataframe")
st.write(date_issue_pl.dtypes)
date_issue_pl = date_issue_pl.with_columns(pl.col("Date").dt.date().alias('Date'))
st.write("After converting date type in polars dataframe")
st.write(date_issue_pl.dtypes)
st.write("This is dataframe")
st.dataframe(date_issue_pl)
st.write("This is st.write")
st.write(date_issue_pl)
st.write("This is st.table")
st.table(date_issue_pl)
App screenshot:
I have tried this same code in Jupyter notebook as well and there Polars Date column is getting displayed as Date column only.
So it seems like an issue when I run it in streamlit.
Version
Python 3.12.4
streamlit==1.38.0
pandas==2.2.2
polars==1.6.0
Originally faced this issue on streamlit hosted app streamlit hosted app
Appreciate any help here !!