From 725f1b861cfb59e0875369428e669664ff02b921 Mon Sep 17 00:00:00 2001 From: Jeff Carey Date: Tue, 6 Dec 2016 19:48:37 -0800 Subject: [PATCH 1/3] BUG: Spurious IncompatibleFrequency error prevented plotting of non-standard intervals (Fixes #14763) --- pandas/src/period.pyx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/src/period.pyx b/pandas/src/period.pyx index 5565f25937394..f1d5a44935db1 100644 --- a/pandas/src/period.pyx +++ b/pandas/src/period.pyx @@ -468,7 +468,7 @@ def extract_ordinals(ndarray[object] values, freq): ndarray[int64_t] ordinals = np.empty(n, dtype=np.int64) object p - freqstr = Period._maybe_convert_freq(freq).freqstr + rule_code = Period._maybe_convert_freq(freq).rule_code for i in range(n): p = values[i] @@ -478,9 +478,9 @@ def extract_ordinals(ndarray[object] values, freq): else: try: ordinals[i] = p.ordinal - - if p.freqstr != freqstr: - msg = _DIFFERENT_FREQ_INDEX.format(freqstr, p.freqstr) + ordinal_rule_code = Period._maybe_convert_freq(p.freq).rule_code + if ordinal_rule_code != rule_code: + msg = _DIFFERENT_FREQ_INDEX.format(ordinal_rule_code, rule_code) raise IncompatibleFrequency(msg) except AttributeError: From 239a4f474ba427d1887460510e43e235e3d368c9 Mon Sep 17 00:00:00 2001 From: Jeff Carey Date: Sat, 10 Dec 2016 00:50:37 -0800 Subject: [PATCH 2/3] BUG: Spurious IncompatibleFrequency error prevented plotting of non-standard intervals (Fixes #14763) --- pandas/src/period.pyx | 10 ++++++---- pandas/tests/plotting/test_series.py | 5 +++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pandas/src/period.pyx b/pandas/src/period.pyx index f1d5a44935db1..956f066187ce8 100644 --- a/pandas/src/period.pyx +++ b/pandas/src/period.pyx @@ -468,7 +468,8 @@ def extract_ordinals(ndarray[object] values, freq): ndarray[int64_t] ordinals = np.empty(n, dtype=np.int64) object p - rule_code = Period._maybe_convert_freq(freq).rule_code + freqstr = Period._maybe_convert_freq(freq).freqstr + base_freq = frequencies.get_base_alias(freqstr) for i in range(n): p = values[i] @@ -478,9 +479,10 @@ def extract_ordinals(ndarray[object] values, freq): else: try: ordinals[i] = p.ordinal - ordinal_rule_code = Period._maybe_convert_freq(p.freq).rule_code - if ordinal_rule_code != rule_code: - msg = _DIFFERENT_FREQ_INDEX.format(ordinal_rule_code, rule_code) + + p_base_freq = frequencies.get_base_alias(p.freqstr) + if p_base_freq != base_freq: + msg = _DIFFERENT_FREQ_INDEX.format(base_freq, p_base_freq) raise IncompatibleFrequency(msg) except AttributeError: diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index e752197c6ad77..c453b7646c6b7 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -802,6 +802,11 @@ def test_custom_business_day_freq(self): _check_plot_works(s.plot) + def test_non_standard_intervals(self): + idx = pd.period_range('2000-01-01', '2000-01-05', freq='6H') + s = Series(np.random.randn(len(idx)), index=idx) + ax = _check_plot_works(s.plot) + if __name__ == '__main__': nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'], From fb5f0463ce01ffb518d3eeeb71def00365c1f63c Mon Sep 17 00:00:00 2001 From: Jeff Carey Date: Sat, 10 Dec 2016 00:53:47 -0800 Subject: [PATCH 3/3] Removed unused variable --- pandas/tests/plotting/test_series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index c453b7646c6b7..01ba0d99ee472 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -805,7 +805,7 @@ def test_custom_business_day_freq(self): def test_non_standard_intervals(self): idx = pd.period_range('2000-01-01', '2000-01-05', freq='6H') s = Series(np.random.randn(len(idx)), index=idx) - ax = _check_plot_works(s.plot) + _check_plot_works(s.plot) if __name__ == '__main__':