Skip to content

dates.date2num bug with daylight switching hour #3896

@kdebrab

Description

@kdebrab

When plotting datetime values using date2num, something strange happens around the hour of daylight switching (matplotlib 1.4.2, pandas 0.15.1, numpy 1.9.1) as shown in the following graph:

import matplotlib.pyplot as plt
import datetime as dt
import pandas as pd
import pytz
from matplotlib.dates import date2num

dt64_utc = pd.date_range(start='2014/03/29 22:00', end='2014/03/30 6:00', freq='min', tz='UTC')
dtmpl_utc = date2num(dt64_utc.astype(dt.datetime))
dt64_bxl = dt64_utc.tz_convert(pytz.timezone('Europe/Brussels'))
dtmpl_bxl = date2num(dt64_bxl.astype(dt.datetime))
dtmpl_bxl_utc = date2num(dt64_bxl.tz_convert('UTC').astype(dt.datetime))
plt.plot(dtmpl_utc, dtmpl_bxl, 'g', label='implicit conversion to UTC by date2num')
plt.plot(dtmpl_utc, dtmpl_bxl_utc, 'b--', label='explicit conversion to UTC before calling date2num')
plt.gca().xaxis_date()
plt.gca().yaxis_date()
plt.grid()
plt.legend()

date2num bug

I assume this is a bug in date2num?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions