Skip to content

Commit bcdc6d9

Browse files
committed
BUG: infer_freq results in None with hourly timezone
1 parent fa21ad8 commit bcdc6d9

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

pandas/tseries/frequencies.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,8 +668,12 @@ class _FrequencyInferer(object):
668668
def __init__(self, index, warn=True):
669669
self.index = index
670670
self.values = np.asarray(index).view('i8')
671+
671672
if index.tz is not None:
672-
self.values = tslib.date_normalize(self.values, index.tz)
673+
f = lambda x: tslib.tz_convert_single(x, 'UTC', index.tz)
674+
self.values = np.vectorize(f)(self.values)
675+
# This cant work, because of DST
676+
# self.values = tslib.tz_convert(self.values, 'UTC', index.tz)
673677

674678
self.warn = warn
675679

pandas/tseries/tests/test_frequencies.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
import pandas.tseries.frequencies as fmod
1515
import pandas.tseries.offsets as offsets
1616
from pandas.tseries.period import PeriodIndex
17-
18-
import pandas.lib as lib
17+
import pandas.compat as compat
1918

2019
from pandas import _np_version_under1p7
2120
import pandas.util.testing as tm
@@ -258,19 +257,20 @@ def test_infer_freq(self):
258257

259258
def test_infer_freq_tz(self):
260259

260+
freqs = {'AS-JAN': ['2009-01-01', '2010-01-01', '2011-01-01', '2012-01-01'],
261+
'Q-OCT': ['2009-01-31', '2009-04-30', '2009-07-31', '2009-10-31'],
262+
'M': ['2010-11-30', '2010-12-31', '2011-01-31', '2011-02-28'],
263+
'W-SAT': ['2010-12-25', '2011-01-01', '2011-01-08', '2011-01-15'],
264+
'D': ['2011-01-01', '2011-01-02', '2011-01-03', '2011-01-04'],
265+
'H': ['2011-12-31 22:00', '2011-12-31 23:00', '2012-01-01 00:00', '2012-01-01 01:00']
266+
}
267+
261268
# GH 7310
262-
for tz in [None, 'Asia/Tokyo', 'US/Pacific', 'Europe/Paris']:
263-
dates = ['2010-11-30', '2010-12-31', '2011-01-31', '2011-02-28']
264-
idx = DatetimeIndex(dates)
265-
self.assertEqual(idx.inferred_freq, 'M')
266-
267-
dates = ['2011-01-01', '2011-01-02', '2011-01-03', '2011-01-04']
268-
idx = DatetimeIndex(dates)
269-
self.assertEqual(idx.inferred_freq, 'D')
270-
271-
dates = ['2011-12-31 22:00', '2011-12-31 23:00', '2012-01-01 00:00', '2012-01-01 01:00']
272-
idx = DatetimeIndex(dates)
273-
self.assertEqual(idx.inferred_freq, 'H')
269+
for tz in [None, 'Australia/Sydney', 'Asia/Tokyo', 'Europe/Paris',
270+
'US/Pacific', 'US/Eastern']:
271+
for expected, dates in compat.iteritems(freqs):
272+
idx = DatetimeIndex(dates, tz=tz)
273+
self.assertEqual(idx.inferred_freq, expected)
274274

275275
def test_not_monotonic(self):
276276
rng = _dti(['1/31/2000', '1/31/2001', '1/31/2002'])

0 commit comments

Comments
 (0)