question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fix naive-datetime timezone conversion when marshaling dataframes

See original GitHub issue

Getting a NonExistentTimeError when marshalling naive datetimes in Pandas dataframes. Specifically when marshaling 2020-8-3 2:30 from a user in PST timezone.

Related to discussion

This is because in the US, daylight savings time starts at 2 am and clocks are turned forward one hour to 3 am, so 2:30 doesn’t exist on March 8. This is fine. However, I never said my datetime was in a US timezone, or any timezone at all. Streamlit localized my datetime to some timezone (presumably ‘America/Los_Angeles’, as I’m in San Francisco).

The code in question is in the _marshall_any_array function in elements/data_frame_proto.py. There’s even a note that says # TODO(armando): Convert eveything to UTC not local timezone. Converting to UTC is an improvement, but still not as good as just leaving it alone and displaying it as is.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
skovhuscommented, Jun 10, 2020

An alternative might be setting the timezone environment variable:

import os

os.environ['TZ'] = 'UTC' # Hardcoded as workaround to  https://github.com/streamlit/streamlit/issues/1061
2reactions
karriebearcommented, Jun 10, 2020

@crypticintent’s solution is definitely the right approach. Any datetimes that have a timezone will be left as is. Thanks for sharing that!

Unfortunately our current implementation of timezone awareness is not correct but it is something we are actively looking into. Forcing timezone awareness helps us ensure datetimes display in sync between the browser and server side, especially when they are in different timezones.

We’re hoping to have a solution out that will support as many use cases as possible. In the meantime, we’ll take a look at expediting a fix to localize to UTC if no timezone exists.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Converting a naive datetime column to a new timezone ...
I have the following dataframe, named 'ORDdataM', with a DateTimeIndex column 'date', and a price point column 'ORDprice'. The date column has ...
Read more >
pytz convert timezone to utc - LRS Realty & Management
This is used to localize a naive datetime (datetime with no timezone San Francisco ... How to convert a time to UTC before...
Read more >
How to remove timezone from a Timestamp column in a ...
import pandas as pd. from datetime import datetime, timezone. # CREATE THE PANDAS DATAFRAME. # WITH TIMESTAMP COLUMN. df = pd.DataFrame({.
Read more >
Disable Streamlit Auto-Converting Timezone To Local - ADocLib
By default, Schemas will marshal the object attributes that are identical to the schema's field Timezone-naive datetime objects are converted to UTC (+00:00)...
Read more >
NaiveDateTime in chrono::naive - Rust - Docs.rs
This can fail in cases where the local time represented by the NaiveDateTime is not a valid local timestamp in the target timezone...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found