streamlit icon indicating copy to clipboard operation
streamlit copied to clipboard

Error: Unrecognized type: "Duration" (18)

Open felp99 opened this issue 2 years ago • 11 comments

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)

felp99 avatar Mar 10 '22 14:03 felp99

Hello @felp99 . Could you please provide more context for the issue?

kajarenc avatar Mar 10 '22 15:03 kajarenc

I've had the same issue when trying to use


st.write(df.dtypes.astype(str))
st.dataframe(df)

where the first line prints (among other things

...
Duration       timedelta64[ns]
...

And the error message shown in streamlit is:

Error: Unrecognized type: "Duration" (18)

$n.decode@http://192.168.0.102:8501/static/js/5.c7ec7886.chunk.js:2:3067053
Ki@http://192.168.0.102:8501/static/js/5.c7ec7886.chunk.js:2:3064118
Yn.decode@http://192.168.0.102:8501/static/js/5.c7ec7886.chunk.js:2:3068206
value/a._createHeader@http://192.168.0.102:8501/static/js/5.c7ec7886.chunk.js:2:3061719
value@http://192.168.0.102:8501/static/js/5.c7ec7886.chunk.js:2:3060864
value@http://192.168.0.102:8501/static/js/5.c7ec7886.chunk.js:2:3071207
value@http://192.168.0.102:8501/static/js/5.c7ec7886.chunk.js:2:3131777
value@http://192.168.0.102:8501/static/js/5.c7ec7886.chunk.js:2:3126807
value@http://192.168.0.102:8501/static/js/5.c7ec7886.chunk.js:2:3121356
e@http://192.168.0.102:8501/static/js/main.3fe58c98.chunk.js:2:10639
get@http://192.168.0.102:8501/static/js/main.3fe58c98.chunk.js:2:425090
ln@http://192.168.0.102:8501/static/js/main.3fe58c98.chunk.js:2:457494
ia@http://192.168.0.102:8501/static/js/5.c7ec7886.chunk.js:2:3254431
Gs@http://192.168.0.102:8501/static/js/5.c7ec7886.chunk.js:2:3306889
Ml@http://192.168.0.102:8501/static/js/5.c7ec7886.chunk.js:2:3294065
Cl@http://192.168.0.102:8501/static/js/5.c7ec7886.chunk.js:2:3293993
Sl@http://192.168.0.102:8501/static/js/5.c7ec7886.chunk.js:2:3293854
gl@http://192.168.0.102:8501/static/js/5.c7ec7886.chunk.js:2:3290820
qi/<@http://192.168.0.102:8501/static/js/5.c7ec7886.chunk.js:2:3240199
t.unstable_runWithPriority@http://192.168.0.102:8501/static/js/5.c7ec7886.chunk.js:2:3317618
Ui@http://192.168.0.102:8501/static/js/5.c7ec7886.chunk.js:2:3239976
qi@http://192.168.0.102:8501/static/js/5.c7ec7886.chunk.js:2:3240146
Gi@http://192.168.0.102:8501/static/js/5.c7ec7886.chunk.js:2:3240079
dl@http://192.168.0.102:8501/static/js/5.c7ec7886.chunk.js:2:3288189
enqueueSetState@http://192.168.0.102:8501/static/js/5.c7ec7886.chunk.js:2:3244097
g.prototype.setState@http://192.168.0.102:8501/static/js/5.c7ec7886.chunk.js:2:3190437
3156/n/r.handleDeltaMsg/<@http://192.168.0.102:8501/static/js/main.3fe58c98.chunk.js:2:558852

A naive approach, renaming the column, did not help...

david-huck avatar Mar 12 '22 13:03 david-huck

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:

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)

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

kajarenc avatar Mar 17 '22 15:03 kajarenc

I had the same problem with timedelta64[ns] value in dataframe resulting in Error: Unrecognized type: "Duration" (18)

However, changing dataFrameSerialization = "legacy" did not solve my problem, I got NotImplementedError: Dtype category not understood instead.

tarmojuristo avatar Mar 30 '22 11:03 tarmojuristo

Same problem. Temporarily working with:

st.code(df)

bdthombre avatar Apr 24 '22 18:04 bdthombre

Any update on this? Has anyone found a solution or temporary work-around?

GeorgeVJose avatar May 27 '22 23:05 GeorgeVJose

It’s solved in GitHub. Check the link

Enviado do meu iPhone

Em 27 de mai. de 2022, à(s) 20:31, George V Jose @.***> escreveu:

 Any update on this? Has anyone found a solution or temporary work-around?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.

felp99 avatar May 27 '22 23:05 felp99

Adding some info I just collected on this, so it's easier to fix later:

  • Streamlit uses Apache Arrow to serialize dataframes and send them from Python to JS
  • I don't know if it matters, but on the JS side Streamlit uses Arrow v7.
  • The upstream version of Arrow JS is already at v8. Upgrading could help.
  • The Jira board for Arrow JS has an open bug that sounds like this one, though, so it's possible upgrading will not help after all.

tvst avatar Jun 07 '22 18:06 tvst

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 legacy serialization as described here or convert the timedelta value to int via df["delta"].dt.days or df["delta"].dt.seconds. For example:

import pandas as pd
import streamlit as st

data = {
    "dt1": ["2020-01-03 12:23", "2020-04-12 12:34"],
    "dt2": ["2021-03-23 12:13", "2021-12-12 11:04"],
}

df = pd.DataFrame(data)
df["dt1"] = pd.to_datetime(df["dt1"])
df["dt2"] = pd.to_datetime(df["dt2"])
df["delta"] = df["dt2"] - df["dt1"]

# Convert to integer value:
df["delta"] = df["delta"].dt.days

st.dataframe(df)

lukasmasuch avatar Jun 10 '22 14:06 lukasmasuch

I have the same problem when displaying a pd.DataFrame with a column of datetime.timedelta objects.

andrader avatar Aug 26 '22 14:08 andrader

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)

nafets33 avatar Sep 02 '22 17:09 nafets33

Append or column.dtype == 'timedelta64[ns]' to https://github.com/streamlit/streamlit/blob/d774bedfb3712fa9124ea57c94ed5628fbd06626/lib/streamlit/type_util.py#L613 fix the problem for me. In some cases, also need to add df = fix_arrow_incompatible_column_types(df) in front of https://github.com/streamlit/streamlit/blob/d774bedfb3712fa9124ea57c94ed5628fbd06626/lib/streamlit/type_util.py#L669 to force conversion.

dodid avatar Nov 05 '22 04:11 dodid

Still hoping for a fix to this issue..

flight505 avatar Jan 03 '23 10:01 flight505

Yes, running into this issue as well.

shivan-s avatar Jan 03 '23 21:01 shivan-s

Any update here? Currently running into this problem...

HWiese1980 avatar Mar 25 '23 11:03 HWiese1980

same here, not able to fix this issue when taking both time and date as input

Error: Unrecognized type: "Duration" (18)
at Zi (http://localhost:8501/static/js/main.5e4731c6.js:2:1300567)
at gr.decode (http://localhost:8501/static/js/main.5e4731c6.js:2:1301753)
at Ui (http://localhost:8501/static/js/main.5e4731c6.js:2:1299119)
at Mr.decode (http://localhost:8501/static/js/main.5e4731c6.js:2:1302895)
at e._createHeader (http://localhost:8501/static/js/main.5e4731c6.js:2:1296724)
at e.value (http://localhost:8501/static/js/main.5e4731c6.js:2:1295890)
at r.value (http://localhost:8501/static/js/main.5e4731c6.js:2:1320472)
at Function.from (<anonymous>)
at r (http://localhost:8501/static/js/main.5e4731c6.js:2:3571164)
at a (http://localhost:8501/static/js/main.5e4731c6.js:2:3581091)

Adithya-Shetty100 avatar May 06 '23 13:05 Adithya-Shetty100

same here. I have problems with timedelta type variables. Funny enough the same code runs ok locally but not when commited to github and deployed on Streamlit cloud. Has anyone heard whether it is being worked on and what priority it has been given?

bobiq avatar May 20 '23 20:05 bobiq

The error I get:

File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 565, in _run_script

exec(code, module.__dict__)

File "/app/youtube_channels_by_topic_streamlit/YouTube_channels_by_topic_streamlit.py", line 356, in

video_df['likes_per_second']=video_df['likeCount']/video_df['durationSecs']

File "/home/appuser/venv/lib/python3.9/site-packages/pandas/core/ops/common.py", line 81, in new_method

return method(self, other)

File "/home/appuser/venv/lib/python3.9/site-packages/pandas/core/arraylike.py", line 210, in truediv

return self._arith_method(other, operator.truediv)

File "/home/appuser/venv/lib/python3.9/site-packages/pandas/core/series.py", line 6108, in _arith_method

return base.IndexOpsMixin._arith_method(self, other, op)

File "/home/appuser/venv/lib/python3.9/site-packages/pandas/core/base.py", line 1348, in _arith_method

result = ops.arithmetic_op(lvalues, rvalues, op)

File "/home/appuser/venv/lib/python3.9/site-packages/pandas/core/ops/array_ops.py", line 224, in arithmetic_op

res_values = op(left, right)

File "/home/appuser/venv/lib/python3.9/site-packages/pandas/core/arrays/datetimelike.py", line 1993, in array_ufunc

return super().__array_ufunc__(ufunc, method, *inputs, **kwargs)

File "/home/appuser/venv/lib/python3.9/site-packages/pandas/core/arrays/base.py", line 1686, in array_ufunc

return arraylike.default_array_ufunc(self, ufunc, method, *inputs, **kwargs)

File "/home/appuser/venv/lib/python3.9/site-packages/pandas/core/arraylike.py", line 489, in default_array_ufunc

return getattr(ufunc, method)(*new_inputs, **kwargs)

numpy.core._exceptions._UFuncBinaryResolutionError: ufunc 'divide' cannot use operands with types dtype('int64') and dtype('<m8[s]')

bobiq avatar May 21 '23 06:05 bobiq

One hack that seems to work is transposing the data such that instead of a column of TimeDelta values, you have a row, eg:

df.loc[:, 'duration'] = df.time - df.time.shift(-1)
df.head().T  # for example

Pk13055 avatar Jul 23 '23 21:07 Pk13055

As a work around you can convert your timedelta to float using total_seconds()

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).total_seconds() for i in range(3)])

df = pd.DataFrame(
    {
        "A": s,
        "B": td
    }
)

st.table(df)

output from your code:

image

QCAsystemsbharvey avatar Oct 10 '23 17:10 QCAsystemsbharvey

@LukasMasuch This will be fixed in the new version of PyArrow/Arrow.js. correct?

I think the fix is here https://github.com/apache/arrow/pull/37341

kmcgrady avatar Nov 07 '23 20:11 kmcgrady

@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

lukasmasuch avatar Nov 08 '23 02:11 lukasmasuch

Hello, I am encountering an issue with my Streamlit application[Chatbot] , where a blank page randomly appears for a random query. I've tried using the dataFrameSerialization = "legacy" approach, but the issue persists. When inspecting the page, the errors I'm seeing look like the following: TypeError: Cannot read properties of undefined (reading 'vertical') at Di (main, 1661a802.js:2:4213879) at wa (main. 1661a802.js:2:2230016) at wl (main.1661a802.js:2:2287129) at ze (main.1661a802.js:2:2276235) at Oc (main.1661a802.js:2:2276163) at Mc (main. 1661a802.js:2:2276026) at cc (main, 16612802.js:2:2273142) at Uo (moin. 1661a802.js:2:2213737) at rc (main.1661a802.js:2:2270229) at Object.enqueueSetState (main.1661a802.js:2:2220755) Uncaught TypeError: Cannot read properties of undefined (reading 'vertical') at Di (main. 1661a802.js:2:4213879) at wa (main.1661a802.js:2:2230016) at wl (moin.1661a802.js:2:2287129) at zc (main.16618802.js:2:2276235) at Oc (main. 1661a802.js:2:2276163) at Mc (main.1661a802.js:2:2276026) at cc (main.1661a802.js:2:2273142) at Uo (main. 1661a802.js:2:2213737) at rc (main.1661a802.js:2:2270229) at Object.enqueueSetState (main, 1661a802.js:2:2220755) Any insights on how to address this would be greatly appreciated.

 Thank you!

Alli118 avatar Apr 16 '24 05:04 Alli118

I see the same thing as @Alli118 - at seemingly random points of interaction with my app I get the TypeError: Cannot read properties of undefined (reading 'vertical') or TypeError: Cannot read properties of undefined (reading 'tab')

itsToggle avatar Apr 24 '24 10:04 itsToggle

@Alli118 @itsToggle I'm also having the same issue of TypeError: Cannot read properties of undefined (reading 'vertical') in the JS console for a random query. But it seems that this error occurs only on the specific page that asks GPT-4 to generate several sentences and asks users to answer some questions regarding the generated sentences by clicking radio buttons. Is it related to the size of state sessions or containers?

mimn97 avatar May 13 '24 19:05 mimn97

@Alli118 @itsToggle @mimn97 I'm pretty sure that the error you are getting is unrelated to this issue. It would be awesome if someone could open a new issue for this error and, if possible, add some minimum reproducible examples to this.

lukasmasuch avatar May 13 '24 19:05 lukasmasuch