Skip to content

Commit 3c5621b

Browse files
committed
BUG: support StaticTzInfo in DatetimeIndex close pandas-dev#1692
1 parent ee6db80 commit 3c5621b

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

RELEASE.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ pandas 0.8.2
8282
- Fix handling of PeriodIndex as argument to create MultiIndex (#1705)
8383
- Fix re: unicode MultiIndex level names in Series/DataFrame repr (#1736)
8484
- Handle PeriodIndex in to_datetime instance method (#1703)
85+
- Support StaticTzInfo in DatetimeIndex infrastructure (#1692)
8586

8687
pandas 0.8.1
8788
============

pandas/src/datetime.pyx

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -550,11 +550,17 @@ cpdef convert_to_tsobject(object ts, object tz=None):
550550
trans = _get_transitions(tz)
551551
deltas = _get_deltas(tz)
552552
pos = trans.searchsorted(obj.value, side='right') - 1
553-
inf = tz._transition_info[pos]
554553

555-
pandas_datetime_to_datetimestruct(obj.value + deltas[pos],
556-
PANDAS_FR_ns, &obj.dts)
557-
obj.tzinfo = tz._tzinfos[inf]
554+
# statictzinfo
555+
if not hasattr(tz, '_transition_info'):
556+
pandas_datetime_to_datetimestruct(obj.value + deltas[0],
557+
PANDAS_FR_ns, &obj.dts)
558+
obj.tzinfo = tz
559+
else:
560+
inf = tz._transition_info[pos]
561+
pandas_datetime_to_datetimestruct(obj.value + deltas[pos],
562+
PANDAS_FR_ns, &obj.dts)
563+
obj.tzinfo = tz._tzinfos[inf]
558564

559565
return obj
560566

@@ -899,16 +905,25 @@ def _get_transitions(tz):
899905
Get UTC times of DST transitions
900906
"""
901907
if tz not in trans_cache:
902-
arr = np.array(tz._utc_transition_times, dtype='M8[ns]')
903-
trans_cache[tz] = arr.view('i8')
908+
if hasattr(tz, '_utc_transition_times'):
909+
arr = np.array(tz._utc_transition_times, dtype='M8[ns]')
910+
arr = arr.view('i8')
911+
else:
912+
arr = np.array([NPY_NAT + 1], dtype=np.int64)
913+
trans_cache[tz] = arr
904914
return trans_cache[tz]
905915

906916
def _get_deltas(tz):
907917
"""
908918
Get UTC offsets in microseconds corresponding to DST transitions
909919
"""
910920
if tz not in utc_offset_cache:
911-
utc_offset_cache[tz] = _unbox_utcoffsets(tz._transition_info)
921+
if hasattr(tz, '_utc_transition_times'):
922+
utc_offset_cache[tz] = _unbox_utcoffsets(tz._transition_info)
923+
else:
924+
# static tzinfo
925+
num = int(total_seconds(tz._utcoffset)) * 1000000000
926+
utc_offset_cache[tz] = np.array([num], dtype=np.int64)
912927
return utc_offset_cache[tz]
913928

914929
cdef double total_seconds(object td): # Python 2.6 compat

pandas/tseries/tests/test_timezones.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,12 @@ def test_tz_aware_asfreq(self):
412412
# it works!
413413
s.asfreq('T')
414414

415+
def test_static_tzinfo(self):
416+
# it works!
417+
index = DatetimeIndex([datetime(2012, 1, 1)], tz='EST')
418+
index.hour
419+
index[0]
420+
415421
class TestTimeZones(unittest.TestCase):
416422

417423
def setUp(self):

0 commit comments

Comments
 (0)