From 999259c98552fbacccfb5d183c951b4f14ec7adf Mon Sep 17 00:00:00 2001 From: sinhrks Date: Tue, 3 Jun 2014 19:39:04 +0900 Subject: [PATCH] BUG: inferred_freq results in None for eastern hemispheres timezones --- doc/source/v0.14.1.txt | 1 + pandas/tseries/frequencies.py | 3 +++ pandas/tseries/tests/test_frequencies.py | 16 ++++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/doc/source/v0.14.1.txt b/doc/source/v0.14.1.txt index 45e0e15d311b4..48eac7fb1b761 100644 --- a/doc/source/v0.14.1.txt +++ b/doc/source/v0.14.1.txt @@ -85,3 +85,4 @@ Bug Fixes - Bug in ``isnull()`` when ``mode.use_inf_as_null == True`` where isnull wouldn't test ``True`` when it encountered an ``inf``/``-inf`` (:issue:`7315`). +- Bug in inferred_freq results in None for eastern hemisphere timezones (:issue:`7310`) diff --git a/pandas/tseries/frequencies.py b/pandas/tseries/frequencies.py index e3c933e116987..70eab4dde8c1f 100644 --- a/pandas/tseries/frequencies.py +++ b/pandas/tseries/frequencies.py @@ -668,6 +668,9 @@ 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) + self.warn = warn if len(index) < 3: diff --git a/pandas/tseries/tests/test_frequencies.py b/pandas/tseries/tests/test_frequencies.py index 076b0e06cdddf..e2e30fcb69440 100644 --- a/pandas/tseries/tests/test_frequencies.py +++ b/pandas/tseries/tests/test_frequencies.py @@ -256,6 +256,22 @@ def test_infer_freq(self): rng = Index(rng.to_timestamp('D', how='e').asobject) self.assertEqual(rng.inferred_freq, 'Q-OCT') + def test_infer_freq_tz(self): + + # 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') + def test_not_monotonic(self): rng = _dti(['1/31/2000', '1/31/2001', '1/31/2002']) rng = rng[::-1]