Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: tslib.tz_convert(vals, tz1, tz2) may raise an IndexError exception. #4496

Closed
stenri opened this issue Aug 7, 2013 · 1 comment
Closed
Labels
Datetime Datetime data dtype
Milestone

Comments

@stenri
Copy link
Contributor

stenri commented Aug 7, 2013

The following code produces "Out of bounds on buffer access (axis 0)" exception when accessing idx.hour:


import pandas as pd

idx = pd.date_range('26/3/2011', '27/3/2011', freq='1min')
idx = idx.tz_localize('UTC')
idx = idx.tz_convert('Europe/Moscow')

hour = idx.hour


Traceback (most recent call last):
File "test.py", line 7, in
hour = idx.hour
File "C:\Python27\lib\site-packages\pandas\tseries\index.py", line 41, in f
values = self._local_timestamps()
File "C:\Python27\lib\site-packages\pandas\tseries\index.py", line 397, in _local_timestamps
return tslib.tz_convert(self.asi8, utc, self.tz)
File "tslib.pyx", line 1356, in pandas.tslib.tz_convert (pandas\tslib.c:21388)
IndexError: Out of bounds on buffer access (axis 0)

My research indicated there was a bug in the following piece of code in tslib.tz_convert(vals, tz1, tz2) in Pandas 0.12. There is no check that "(pos + 1) < len(trans)" when referencing trans[pos + 1] inside the for loop:

        offset = deltas[pos]
        for i in range(n):
            v = utc_dates[i]
            if v >= trans[pos + 1]:
                pos += 1
                offset = deltas[pos]
            result[i] = v + offset

As a result in some circumstances this code raises "Out of bounds on buffer access (axis 0)" exception. For example, in Russia last day-light saving transition took place in somewhere in 26/3/2011-27/3/2011, and there were no transitions since then.

If ts_lib.tz_convert() is asked to convert time zones for interval that includes 26/3/2011-27/3/2011, it raises an exception while trying to access trans[pos + 1].

I have a working patch that solves this. Going to contribute it soon.

stenri added a commit to stenri/pandas that referenced this issue Aug 23, 2013
jreback added a commit that referenced this issue Aug 23, 2013
…1__bugfix

Fix issue #4496: tslib.tz_convert(vals, tz1, tz2) may raise an IndexErro...
@jreback
Copy link
Contributor

jreback commented Aug 23, 2013

closed by #4497

@jreback jreback closed this as completed Aug 23, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype
Projects
None yet
Development

No branches or pull requests

2 participants