Skip to content

Commit 27c4c96

Browse files
committed
BUG: add H,T,S as subperiods of H #1732
1 parent 6a53880 commit 27c4c96

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

pandas/tseries/frequencies.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,12 @@ def is_subperiod(source, target):
944944
return source in ['B', 'H', 'T', 'S']
945945
elif target == 'D':
946946
return source in ['D', 'H', 'T', 'S']
947+
elif target == 'H':
948+
return source in ['H', 'T', 'S']
949+
elif target == 'T':
950+
return source in ['T', 'S']
951+
elif target == 'S':
952+
return source in ['S']
947953

948954
def is_superperiod(source, target):
949955
"""
@@ -988,6 +994,12 @@ def is_superperiod(source, target):
988994
return target in ['D', 'B', 'H', 'T', 'S']
989995
elif source == 'D':
990996
return target in ['D', 'B', 'H', 'T', 'S']
997+
elif source == 'H':
998+
return target in ['H', 'T', 'S']
999+
elif source == 'T':
1000+
return target in ['T', 'S']
1001+
elif source == 'S':
1002+
return target in ['S']
9911003

9921004
def _get_rule_month(source, default='DEC'):
9931005
source = source.upper()

pandas/tseries/tests/test_frequencies.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,10 @@ def test_is_superperiod_subperiod():
202202
assert(fmod.is_superperiod(offsets.YearEnd(), offsets.MonthEnd()))
203203
assert(fmod.is_subperiod(offsets.MonthEnd(), offsets.YearEnd()))
204204

205+
assert(fmod.is_superperiod(offsets.Hour(), offsets.Minute()))
206+
assert(fmod.is_subperiod(offsets.Minute(), offsets.Hour()))
207+
205208
if __name__ == '__main__':
206209
import nose
207210
nose.runmodule(argv=[__file__,'-vvs','-x','--pdb', '--pdb-failure'],
208211
exit=False)
209-

pandas/tseries/tests/test_plotting.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,16 @@ def test_mixed_freq_lf_first(self):
616616
for l in ax.get_lines():
617617
self.assert_(l.get_xdata().freq == 'D')
618618

619+
plt.close('all')
620+
idxh = date_range('1/1/1999', periods=240, freq='T')
621+
idxl = date_range('1/1/1999', periods=4, freq='H')
622+
high = Series(np.random.randn(len(idxh)), idxh)
623+
low = Series(np.random.randn(len(idxl)), idxl)
624+
low.plot()
625+
ax = high.plot()
626+
for l in ax.get_lines():
627+
self.assert_(l.get_xdata().freq == 'T')
628+
619629
@slow
620630
def test_mixed_freq_irreg_period(self):
621631
ts = tm.makeTimeSeries()

0 commit comments

Comments
 (0)