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.

Datetimes on plot are always treated as local time and shifted to UTC

See original GitHub issue
Description

When displaying datetime.datetime values along the x-axis using x_axis_type = "datetime", the values are shifted if the system’s timezone is not UTC.

For example, if you live in UTC-05:00, then all the dates are shifted ahead 5 hours (7am appears at noon).

This happens regardless of the tzinfo on the datetimes, including for naive datetimes where tzinfo is None.

Sample Code
from datetime import datetime
from bokeh.plotting import figure, show
from bokeh.models.sources import ColumnDataSource
from bokeh.models.tools import CrosshairTool, HoverTool

hours = range(24)
datetimes = [datetime.now().replace(hour=h, minute=0, second=0, tzinfo=None) for h in hours]

example = figure(
	x_axis_label = 'Date/Time',
	x_axis_type = 'datetime',
	y_axis_label = 'Expected Hour',
)
example.circle(
	x = 'x',
	y = 'y',
	fill_color = 'blue',
	size = 6,
	source = ColumnDataSource({
		'x': datetimes,
		'y': hours,
		'time_fmt': [dt.strftime("%H:%M") for dt in datetimes],
	}),
)
example.add_tools(CrosshairTool())
example.add_tools(HoverTool(
	tooltips = [
		("index", "$index"),
		("expected time", "@time_fmt"),
	],
))

show(example)
Expected Behaviour

I would have expected that naive datetimes are displayed as is.

Actual Behaviour

screenshot at 2016-12-01 12 53 01

System, Library, Browser, Version information

I am using Python 3.5.2 (64-bit) with bokeh 0.12.3 and Firefox 50.0 as well as Chrome 54.0.2840.100 (64-bit) on Ubuntu MATE 16.04.1 LTS and on CentOS release 6.8.

bokeh info (Ubuntu):

Python version      :  3.5.2 (default, Sep 10 2016, 08:21:44) 
IPython version     :  5.1.0
Bokeh version       :  0.12.3
BokehJS static path :  /usr/local/lib/python3.5/dist-packages/bokeh/server/static

bokeh info (CentOS):

Python version      :  3.5.2 (default, Nov 24 2016, 13:03:33) 
IPython version     :  Not installed
Bokeh version       :  0.12.3
BokehJS static path :  /usr/local/lib/python3.5/site-packages/bokeh/server/static
Other notes

You can work around this issue by setting your system timezone to UTC. This is not ideal though.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:20 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
bryevdvcommented, May 11, 2017

I just pushed this change to the linked PR. With this change, the original code now yields: screen shot 2017-05-11 at 14 40 03

@mwerezak @gismo2004 any chance you can test the PR out by cloning and building bokeh locally?

0reactions
mwerezakcommented, May 17, 2017

Looks like gismo2004 beat me to it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Matplotlib plot_date keeping times in UTC even with custom ...
Matplotlib plot_date keeping times in UTC even with custom Timezone ... I'm using matplotlib to plot data against timestamps in python 2.6. I've...
Read more >
How to display "last updated" information in local time?
Datetime values in Bokeh are always assumed to be local time and are ... on plot are always treated as local time and...
Read more >
datetime — Basic date and time types — Python 3.11.1 ...
Because naive datetime objects are treated by many datetime methods as local times, it is preferred to use aware datetimes to represent times...
Read more >
Back to Basics: UTC and TimeZones in .NET Web Apps
Web apps typically require that dates are stored in time zone agnostic fashion. This means storing DateTime values as UTC, so that you...
Read more >
Will you show me examples of changing time zones with ...
If you have not set the TimeZone on a datetime before, then it does not assume UTC to be converted. Setting the 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