When plotting timeseries data with altair, the timezone appears to be converted from UTC into the browser locale. The underlying data does not contain any timezone information. When an equivalent plot is created in a jupyter notebook, it correctly displays the time as-is, without adjustment.
Steps to reproduce
Run the following and note the difference between the dataframe and the plot (assuming you are not in a UTC+0 timezone)
Code snippet:
import altair as alt
import streamlit as st
import pandas as pd
df = pd.DataFrame({
'datetime': [pd.to_datetime('2023-06-01 12:00')],
'value': [10],
})
df
st.altair_chart(
alt.Chart(df).mark_bar().encode(
x='datetime', y='value')
)
Expected behavior:
The plot should display the time without timezone adjustment.
Actual behavior:
The plot shows the datetime adjusted to my timezone, incorrectly assuming the underlying data is UTC.
Debug info
Streamlit version: Streamlit, version 1.23.1
Python version: Python 3.10.8
OS version: windows 10 20H2 19042.2965
Browser version: Chrome canary 116.0.5813.0 or Edge 114.0.1823.37
A standard timezone-agnostic date/time column in a Pandas dataframe will be both interpreted and displayed as local user time
Streamlit appears to be interpreting the datetime in UTC+0 and displaying in local time. If I use altair directly to plot or save the chart to JSON, there is no timezone conversion.