Skip to content

Commit 8c0e206

Browse files
committed
BUG: fix Cython tz_convert bug with time zones that haven't had a UTC transition in a long time. close #1946
1 parent 36f00e4 commit 8c0e206

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

RELEASE.rst

+2
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ pandas 0.9.0
203203
partial-indexing a hierarchically-indexed DataFrame (#1796)
204204
- Support multiple column selection in DataFrame.__getitem__ with duplicate
205205
columns (#1943)
206+
- Fix time zone localization bug causing improper fields (e.g. hours) in time
207+
zones that have not had a UTC transition in a long time (#1946)
206208

207209
pandas 0.8.1
208210
============

pandas/src/datetime.pyx

+6-1
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ def tz_convert(ndarray[int64_t] vals, object tz1, object tz2):
948948
if pos == 0:
949949
raise ValueError('First time before start of DST info')
950950
elif pos == len(trans):
951-
return result + deltas[-1]
951+
return utc_dates + deltas[-1]
952952

953953
# TODO: this assumed sortedness :/
954954
pos -= 1
@@ -1017,6 +1017,11 @@ def _get_transitions(tz):
10171017
if hasattr(tz, '_utc_transition_times'):
10181018
arr = np.array(tz._utc_transition_times, dtype='M8[ns]')
10191019
arr = arr.view('i8')
1020+
try:
1021+
if tz._utc_transition_times[0].year == 1:
1022+
arr[0] = NPY_NAT + 1
1023+
except Exception:
1024+
pass
10201025
else:
10211026
arr = np.array([NPY_NAT + 1], dtype=np.int64)
10221027
trans_cache[tz] = arr

pandas/tseries/tests/test_timezones.py

+7
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,13 @@ def test_field_access_localize(self):
240240
rng = DatetimeIndex(strdates, tz='US/Eastern')
241241
self.assert_((rng.hour == 0).all())
242242

243+
# a more unusual time zone, #1946
244+
dr = date_range('2011-10-02 00:00', freq='h', periods=10,
245+
tz='America/Atikokan')
246+
247+
expected = np.arange(10)
248+
self.assert_(np.array_equal(dr.hour, expected))
249+
243250
def test_with_tz(self):
244251
tz = pytz.timezone('US/Central')
245252

0 commit comments

Comments
 (0)