Errors with UTC timestamps

18 views
Skip to first unread message

Paul Hobson

unread,
Nov 16, 2012, 1:31:58 PM11/16/12
to pyd...@googlegroups.com
Hey folks,

I noticed that if try to build a DatetimeIndex doesn't play nice with matplotlib's date module. Consider the following:
In [1]: import pandas

In [2]: import datetime

In [3]: import matplotlib.dates as mdates

In [4]: start = mdates.num2date(mdates.datestr2num('2012-1-1'))

In [5]: end = mdates.num2date(mdates.datestr2num('2012-6-1'))

In [6]: pandas.DatetimeIndex(start=start, end=end, freq='MS')
---------------------------------------------------------------------------

AttributeError: '_UTC' object has no attribute 'normalize'

In [7]: pandas.version.version
Out[7]: '0.9.1'

In [8]: start
Out[8]: datetime.datetime(2012, 1, 1, 0, 0, tzinfo=<matplotlib.dates._UTC object at 0x04C92130>)

Setting matplotib.rcParams['timezone'] to *anything* that's not UTC fixes this problem

My guess is that isn't a big deal since pandas can parse the datestrings as well as matplotlib, making lines 4 and 5 unnecessary. Perhaps an note in the docs is in order? If so, that's something I'd be willing to take on myself and submit a PR. Should I also check in with the MPL devs about this?

Thanks,
-paul
Reply all
Reply to author
Forward
0 new messages