Skip to content

BUG: infer_freq results in None for hourly freq with timezone #7371

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

Merged
merged 1 commit into from
Jun 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pandas/tseries/frequencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,12 @@ class _FrequencyInferer(object):
def __init__(self, index, warn=True):
self.index = index
self.values = np.asarray(index).view('i8')

if index.tz is not None:
self.values = tslib.date_normalize(self.values, index.tz)
f = lambda x: tslib.tz_convert_single(x, 'UTC', index.tz)
self.values = np.vectorize(f)(self.values)
# This cant work, because of DST
# self.values = tslib.tz_convert(self.values, 'UTC', index.tz)

self.warn = warn

Expand Down
28 changes: 14 additions & 14 deletions pandas/tseries/tests/test_frequencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
import pandas.tseries.frequencies as fmod
import pandas.tseries.offsets as offsets
from pandas.tseries.period import PeriodIndex

import pandas.lib as lib
import pandas.compat as compat

from pandas import _np_version_under1p7
import pandas.util.testing as tm
Expand Down Expand Up @@ -258,19 +257,20 @@ def test_infer_freq(self):

def test_infer_freq_tz(self):

freqs = {'AS-JAN': ['2009-01-01', '2010-01-01', '2011-01-01', '2012-01-01'],
'Q-OCT': ['2009-01-31', '2009-04-30', '2009-07-31', '2009-10-31'],
'M': ['2010-11-30', '2010-12-31', '2011-01-31', '2011-02-28'],
'W-SAT': ['2010-12-25', '2011-01-01', '2011-01-08', '2011-01-15'],
'D': ['2011-01-01', '2011-01-02', '2011-01-03', '2011-01-04'],
'H': ['2011-12-31 22:00', '2011-12-31 23:00', '2012-01-01 00:00', '2012-01-01 01:00']
}

# GH 7310
for tz in [None, 'Asia/Tokyo', 'US/Pacific', 'Europe/Paris']:
dates = ['2010-11-30', '2010-12-31', '2011-01-31', '2011-02-28']
idx = DatetimeIndex(dates)
self.assertEqual(idx.inferred_freq, 'M')

dates = ['2011-01-01', '2011-01-02', '2011-01-03', '2011-01-04']
idx = DatetimeIndex(dates)
self.assertEqual(idx.inferred_freq, 'D')

dates = ['2011-12-31 22:00', '2011-12-31 23:00', '2012-01-01 00:00', '2012-01-01 01:00']
idx = DatetimeIndex(dates)
self.assertEqual(idx.inferred_freq, 'H')
for tz in [None, 'Australia/Sydney', 'Asia/Tokyo', 'Europe/Paris',
'US/Pacific', 'US/Eastern']:
for expected, dates in compat.iteritems(freqs):
idx = DatetimeIndex(dates, tz=tz)
self.assertEqual(idx.inferred_freq, expected)

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