streamlit: Error: Unrecognized type: "Duration" (18)
Summary
The dataframe shows an error on the frontend if a duration type (timedelta) is used.
Steps to reproduce
import pandas as pd
import streamlit as st
s = pd.Series(pd.date_range("2012-1-1", periods=3, freq="D"))
td = pd.Series([pd.Timedelta(days=i) for i in range(3)])
df = pd.DataFrame(
{
"A": s,
"B": td
}
)
st.table(df)
at Ji (http://localhost:8501/static/js/5.cbb83f60.chunk.js:2:3064094)
at Function.$n.decode (http://localhost:8501/static/js/5.cbb83f60.chunk.js:2:3065289)
at Ki (http://localhost:8501/static/js/5.cbb83f60.chunk.js:2:3062354)
at Function.Yn.decode (http://localhost:8501/static/js/5.cbb83f60.chunk.js:2:3066440)
at e._createHeader (http://localhost:8501/static/js/5.cbb83f60.chunk.js:2:3059955)
at e.value (http://localhost:8501/static/js/5.cbb83f60.chunk.js:2:3059100)
at e.value (http://localhost:8501/static/js/5.cbb83f60.chunk.js:2:3069443)
at n.value (http://localhost:8501/static/js/5.cbb83f60.chunk.js:2:3130013)
at n.value (http://localhost:8501/static/js/5.cbb83f60.chunk.js:2:3125043)
at Function.value (http://localhost:8501/static/js/5.cbb83f60.chunk.js:2:3119592)
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 7
- Comments: 22 (1 by maintainers)
Any update here? Currently running into this problem…
Still hoping for a fix to this issue…
Same problem. Temporarily working with:
st.code(df)Yes, running into this issue as well.
I also did a quick check today into this issue. The duration type is only partially implemented in the javascript/typescript version of Arrow. For example, it is missing here: https://github.com/apache/arrow/blob/f5166fe21969d19adff23fc840ed1d7511348bad/js/src/ipc/metadata/message.ts#L440 I assume it just never got fully implemented yet. Feel free to leave an upvote on this Jira Issue to get some more attention on this.
In the meantime, a workaround would be either to use
legacyserialization as described here or convert thetimedeltavalue tointviadf["delta"].dt.daysordf["delta"].dt.seconds. For example:Thank you @felp99 and @david-huck !
We were able to reproduce the issue and can confirm that the bug exists.
The minimal code snippet that I used for verification is this:
As a workaround for now you can use
dataFrameSerialization = "legacy"config option to switch to a legacy way of data frame serialization. I checked it and with
dataFrameSerialization = "legacy"it works for time delta serialization.Please see https://docs.streamlit.io/library/advanced-features/configuration for more information
@kmcgrady Yes, the new ArrowJS release finally provides support for the Duration type 🎉 However, we still have to do a few things on our side to actually make it work. I’m implementing the changes here: https://github.com/streamlit/streamlit/pull/7689
I’ve had the same issue when trying to use
where the first line prints (among other things
And the error message shown in streamlit is:
A naive approach, renaming the column, did not help…
I added timezone to my dates which works! to get around this error for displaying timedeltas
est = pytz.timezone(“America/New_York”) s = datetime.datetime.now().astimezone(est) e = datetime.datetime.now().astimezone(est) delta = (e-s)