Python pandas.tseries.offsets.Hour() Examples
The following are 30
code examples of pandas.tseries.offsets.Hour().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pandas.tseries.offsets
, or try the search function
.
Example #1
Source File: test_libfrequencies.py From vnpy_crypto with MIT License | 7 votes |
def test_is_superperiod_subperiod(): # input validation assert not (is_superperiod(offsets.YearEnd(), None)) assert not (is_subperiod(offsets.MonthEnd(), None)) assert not (is_superperiod(None, offsets.YearEnd())) assert not (is_subperiod(None, offsets.MonthEnd())) assert not (is_superperiod(None, None)) assert not (is_subperiod(None, None)) assert (is_superperiod(offsets.YearEnd(), offsets.MonthEnd())) assert (is_subperiod(offsets.MonthEnd(), offsets.YearEnd())) assert (is_superperiod(offsets.Hour(), offsets.Minute())) assert (is_subperiod(offsets.Minute(), offsets.Hour())) assert (is_superperiod(offsets.Second(), offsets.Milli())) assert (is_subperiod(offsets.Milli(), offsets.Second())) assert (is_superperiod(offsets.Milli(), offsets.Micro())) assert (is_subperiod(offsets.Micro(), offsets.Milli())) assert (is_superperiod(offsets.Micro(), offsets.Nano())) assert (is_subperiod(offsets.Nano(), offsets.Micro()))
Example #2
Source File: test_libfrequencies.py From twitter-stock-recommendation with MIT License | 6 votes |
def test_is_superperiod_subperiod(): # input validation assert not (is_superperiod(offsets.YearEnd(), None)) assert not (is_subperiod(offsets.MonthEnd(), None)) assert not (is_superperiod(None, offsets.YearEnd())) assert not (is_subperiod(None, offsets.MonthEnd())) assert not (is_superperiod(None, None)) assert not (is_subperiod(None, None)) assert (is_superperiod(offsets.YearEnd(), offsets.MonthEnd())) assert (is_subperiod(offsets.MonthEnd(), offsets.YearEnd())) assert (is_superperiod(offsets.Hour(), offsets.Minute())) assert (is_subperiod(offsets.Minute(), offsets.Hour())) assert (is_superperiod(offsets.Second(), offsets.Milli())) assert (is_subperiod(offsets.Milli(), offsets.Second())) assert (is_superperiod(offsets.Milli(), offsets.Micro())) assert (is_subperiod(offsets.Micro(), offsets.Milli())) assert (is_superperiod(offsets.Micro(), offsets.Nano())) assert (is_subperiod(offsets.Nano(), offsets.Micro()))
Example #3
Source File: test_timezones.py From Computable with MIT License | 6 votes |
def test_tz_localize_dti(self): from pandas.tseries.offsets import Hour dti = DatetimeIndex(start='1/1/2005', end='1/1/2005 0:00:30.256', freq='L') dti2 = dti.tz_localize('US/Eastern') dti_utc = DatetimeIndex(start='1/1/2005 05:00', end='1/1/2005 5:00:30.256', freq='L', tz='utc') self.assert_(np.array_equal(dti2.values, dti_utc.values)) dti3 = dti2.tz_convert('US/Pacific') self.assert_(np.array_equal(dti3.values, dti_utc.values)) dti = DatetimeIndex(start='11/6/2011 1:59', end='11/6/2011 2:00', freq='L') self.assertRaises(pytz.AmbiguousTimeError, dti.tz_localize, 'US/Eastern') dti = DatetimeIndex(start='3/13/2011 1:59', end='3/13/2011 2:00', freq='L') self.assertRaises( pytz.NonExistentTimeError, dti.tz_localize, 'US/Eastern')
Example #4
Source File: test_timeseries.py From Computable with MIT License | 6 votes |
def test_timedelta(self): # this is valid too index = date_range('1/1/2000', periods=50, freq='B') shifted = index + timedelta(1) back = shifted + timedelta(-1) self.assert_(tm.equalContents(index, back)) self.assertEqual(shifted.freq, index.freq) self.assertEqual(shifted.freq, back.freq) result = index - timedelta(1) expected = index + timedelta(-1) self.assert_(result.equals(expected)) # GH4134, buggy with timedeltas rng = date_range('2013', '2014') s = Series(rng) result1 = rng - pd.offsets.Hour(1) result2 = DatetimeIndex(s - np.timedelta64(100000000)) result3 = rng - np.timedelta64(100000000) result4 = DatetimeIndex(s - pd.offsets.Hour(1)) self.assert_(result1.equals(result4)) self.assert_(result2.equals(result3))
Example #5
Source File: test_timezones.py From Computable with MIT License | 6 votes |
def test_with_tz(self): tz = pytz.timezone('US/Central') # just want it to work start = datetime(2011, 3, 12, tzinfo=pytz.utc) dr = bdate_range(start, periods=50, freq=datetools.Hour()) self.assert_(dr.tz is pytz.utc) # DateRange with naive datetimes dr = bdate_range('1/1/2005', '1/1/2009', tz=pytz.utc) dr = bdate_range('1/1/2005', '1/1/2009', tz=tz) # normalized central = dr.tz_convert(tz) self.assert_(central.tz is tz) self.assert_(central[0].tz is tz) # datetimes with tzinfo set dr = bdate_range(datetime(2005, 1, 1, tzinfo=pytz.utc), '1/1/2009', tz=pytz.utc) self.assertRaises(Exception, bdate_range, datetime(2005, 1, 1, tzinfo=pytz.utc), '1/1/2009', tz=tz)
Example #6
Source File: test_frequencies.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def test_is_superperiod_subperiod(): # input validation assert not (frequencies.is_superperiod(offsets.YearEnd(), None)) assert not (frequencies.is_subperiod(offsets.MonthEnd(), None)) assert not (frequencies.is_superperiod(None, offsets.YearEnd())) assert not (frequencies.is_subperiod(None, offsets.MonthEnd())) assert not (frequencies.is_superperiod(None, None)) assert not (frequencies.is_subperiod(None, None)) assert (frequencies.is_superperiod(offsets.YearEnd(), offsets.MonthEnd())) assert (frequencies.is_subperiod(offsets.MonthEnd(), offsets.YearEnd())) assert (frequencies.is_superperiod(offsets.Hour(), offsets.Minute())) assert (frequencies.is_subperiod(offsets.Minute(), offsets.Hour())) assert (frequencies.is_superperiod(offsets.Second(), offsets.Milli())) assert (frequencies.is_subperiod(offsets.Milli(), offsets.Second())) assert (frequencies.is_superperiod(offsets.Milli(), offsets.Micro())) assert (frequencies.is_subperiod(offsets.Micro(), offsets.Milli())) assert (frequencies.is_superperiod(offsets.Micro(), offsets.Nano())) assert (frequencies.is_subperiod(offsets.Nano(), offsets.Micro()))
Example #7
Source File: test_timezones.py From Computable with MIT License | 6 votes |
def test_with_tz_ambiguous_times(self): tz = pytz.timezone('US/Eastern') rng = bdate_range(datetime(2009, 1, 1), datetime(2010, 1, 1)) # March 13, 2011, spring forward, skip from 2 AM to 3 AM dr = date_range(datetime(2011, 3, 13, 1, 30), periods=3, freq=datetools.Hour()) self.assertRaises(pytz.NonExistentTimeError, dr.tz_localize, tz) # after dst transition, it works dr = date_range(datetime(2011, 3, 13, 3, 30), periods=3, freq=datetools.Hour(), tz=tz) # November 6, 2011, fall back, repeat 2 AM hour dr = date_range(datetime(2011, 11, 6, 1, 30), periods=3, freq=datetools.Hour()) self.assertRaises(pytz.AmbiguousTimeError, dr.tz_localize, tz) # UTC is OK dr = date_range(datetime(2011, 3, 13), periods=48, freq=datetools.Minute(30), tz=pytz.utc)
Example #8
Source File: test_timezones.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def test_tzaware_offset(self): dates = date_range('2012-11-01', periods=3, tz='US/Pacific') offset = dates + offsets.Hour(5) assert dates[0] + offsets.Hour(5) == offset[0] # GH 6818 for tz in ['UTC', 'US/Pacific', 'Asia/Tokyo']: dates = date_range('2010-11-01 00:00', periods=3, tz=tz, freq='H') expected = DatetimeIndex(['2010-11-01 05:00', '2010-11-01 06:00', '2010-11-01 07:00'], freq='H', tz=tz) offset = dates + offsets.Hour(5) tm.assert_index_equal(offset, expected) offset = dates + np.timedelta64(5, 'h') tm.assert_index_equal(offset, expected) offset = dates + timedelta(hours=5) tm.assert_index_equal(offset, expected)
Example #9
Source File: test_timezones.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def test_localize_utc_conversion(self): # Localizing to time zone should: # 1) check for DST ambiguities # 2) convert to UTC rng = date_range('3/10/2012', '3/11/2012', freq='30T') converted = rng.tz_localize(self.tzstr('US/Eastern')) expected_naive = rng + offsets.Hour(5) tm.assert_numpy_array_equal(converted.asi8, expected_naive.asi8) # DST ambiguity, this should fail rng = date_range('3/11/2012', '3/12/2012', freq='30T') # Is this really how it should fail?? pytest.raises(NonExistentTimeError, rng.tz_localize, self.tzstr('US/Eastern'))
Example #10
Source File: test_timezones.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_with_tz(self): tz = self.tz('US/Central') # just want it to work start = datetime(2011, 3, 12, tzinfo=pytz.utc) dr = bdate_range(start, periods=50, freq=offsets.Hour()) assert dr.tz is pytz.utc # DateRange with naive datetimes dr = bdate_range('1/1/2005', '1/1/2009', tz=pytz.utc) dr = bdate_range('1/1/2005', '1/1/2009', tz=tz) # normalized central = dr.tz_convert(tz) assert central.tz is tz comp = self.localize(tz, central[0].to_pydatetime().replace( tzinfo=None)).tzinfo assert central[0].tz is comp # compare vs a localized tz comp = self.localize(tz, dr[0].to_pydatetime().replace(tzinfo=None)).tzinfo assert central[0].tz is comp # datetimes with tzinfo set dr = bdate_range(datetime(2005, 1, 1, tzinfo=pytz.utc), '1/1/2009', tz=pytz.utc) pytest.raises(Exception, bdate_range, datetime(2005, 1, 1, tzinfo=pytz.utc), '1/1/2009', tz=tz)
Example #11
Source File: test_timezones.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_ambiguous_infer(self): # November 6, 2011, fall back, repeat 2 AM hour # With no repeated hours, we cannot infer the transition tz = self.tz('US/Eastern') dr = date_range(datetime(2011, 11, 6, 0), periods=5, freq=offsets.Hour()) pytest.raises(pytz.AmbiguousTimeError, dr.tz_localize, tz) # With repeated hours, we can infer the transition dr = date_range(datetime(2011, 11, 6, 0), periods=5, freq=offsets.Hour(), tz=tz) times = ['11/06/2011 00:00', '11/06/2011 01:00', '11/06/2011 01:00', '11/06/2011 02:00', '11/06/2011 03:00'] di = DatetimeIndex(times) localized = di.tz_localize(tz, ambiguous='infer') tm.assert_index_equal(dr, localized) with tm.assert_produces_warning(FutureWarning): localized_old = di.tz_localize(tz, infer_dst=True) tm.assert_index_equal(dr, localized_old) tm.assert_index_equal(dr, DatetimeIndex(times, tz=tz, ambiguous='infer')) # When there is no dst transition, nothing special happens dr = date_range(datetime(2011, 6, 1, 0), periods=10, freq=offsets.Hour()) localized = dr.tz_localize(tz) localized_infer = dr.tz_localize(tz, ambiguous='infer') tm.assert_index_equal(localized, localized_infer) with tm.assert_produces_warning(FutureWarning): localized_infer_old = dr.tz_localize(tz, infer_dst=True) tm.assert_index_equal(localized, localized_infer_old)
Example #12
Source File: test_timezones.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_localize_utc_conversion_explicit(self): # Localizing to time zone should: # 1) check for DST ambiguities # 2) convert to UTC rng = date_range('3/10/2012', '3/11/2012', freq='30T') converted = rng.tz_localize(self.tz('US/Eastern')) expected_naive = rng + offsets.Hour(5) assert np.array_equal(converted.asi8, expected_naive.asi8) # DST ambiguity, this should fail rng = date_range('3/11/2012', '3/12/2012', freq='30T') # Is this really how it should fail?? pytest.raises(NonExistentTimeError, rng.tz_localize, self.tz('US/Eastern'))
Example #13
Source File: test_resample.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_resample_reresample(self): dti = DatetimeIndex(start=datetime(2005, 1, 1), end=datetime(2005, 1, 10), freq='D') s = Series(np.random.rand(len(dti)), dti) bs = s.resample('B', closed='right', label='right').mean() result = bs.resample('8H').mean() assert len(result) == 22 assert isinstance(result.index.freq, offsets.DateOffset) assert result.index.freq == offsets.Hour(8)
Example #14
Source File: test_resample.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_str(self): r = self.series.resample('H') assert ('DatetimeIndexResampler [freq=<Hour>, axis=0, closed=left, ' 'label=left, convention=start, base=0]' in str(r))
Example #15
Source File: test_datetime_index.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_resample_reresample(): dti = date_range(start=datetime(2005, 1, 1), end=datetime(2005, 1, 10), freq='D') s = Series(np.random.rand(len(dti)), dti) bs = s.resample('B', closed='right', label='right').mean() result = bs.resample('8H').mean() assert len(result) == 22 assert isinstance(result.index.freq, offsets.DateOffset) assert result.index.freq == offsets.Hour(8)
Example #16
Source File: test_ticks.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_apply_ticks(): result = offsets.Hour(3).apply(offsets.Hour(4)) exp = offsets.Hour(7) assert (result == exp)
Example #17
Source File: test_frequencies.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_frequency_misc(self): assert (resolution.get_freq_group('T') == FreqGroup.FR_MIN) code, stride = get_freq_code(offsets.Hour()) assert code == FreqGroup.FR_HR code, stride = get_freq_code((5, 'T')) assert code == FreqGroup.FR_MIN assert stride == 5 offset = offsets.Hour() result = frequencies.to_offset(offset) assert result == offset result = frequencies.to_offset((5, 'T')) expected = offsets.Minute(5) assert result == expected with pytest.raises(ValueError, match='Invalid frequency'): get_freq_code((5, 'baz')) with pytest.raises(ValueError, match='Invalid frequency'): frequencies.to_offset('100foo') with pytest.raises(ValueError, match='Could not evaluate'): frequencies.to_offset(('', ''))
Example #18
Source File: test_timezones.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_nat(self): # GH 5546 dates = [NaT] idx = DatetimeIndex(dates) idx = idx.tz_localize('US/Pacific') tm.assert_index_equal(idx, DatetimeIndex(dates, tz='US/Pacific')) idx = idx.tz_convert('US/Eastern') tm.assert_index_equal(idx, DatetimeIndex(dates, tz='US/Eastern')) idx = idx.tz_convert('UTC') tm.assert_index_equal(idx, DatetimeIndex(dates, tz='UTC')) dates = ['2010-12-01 00:00', '2010-12-02 00:00', NaT] idx = DatetimeIndex(dates) idx = idx.tz_localize('US/Pacific') tm.assert_index_equal(idx, DatetimeIndex(dates, tz='US/Pacific')) idx = idx.tz_convert('US/Eastern') expected = ['2010-12-01 03:00', '2010-12-02 03:00', NaT] tm.assert_index_equal(idx, DatetimeIndex(expected, tz='US/Eastern')) idx = idx + offsets.Hour(5) expected = ['2010-12-01 08:00', '2010-12-02 08:00', NaT] tm.assert_index_equal(idx, DatetimeIndex(expected, tz='US/Eastern')) idx = idx.tz_convert('US/Pacific') expected = ['2010-12-01 05:00', '2010-12-02 05:00', NaT] tm.assert_index_equal(idx, DatetimeIndex(expected, tz='US/Pacific')) idx = idx + np.timedelta64(3, 'h') expected = ['2010-12-01 08:00', '2010-12-02 08:00', NaT] tm.assert_index_equal(idx, DatetimeIndex(expected, tz='US/Pacific')) idx = idx.tz_convert('US/Eastern') expected = ['2010-12-01 11:00', '2010-12-02 11:00', NaT] tm.assert_index_equal(idx, DatetimeIndex(expected, tz='US/Eastern'))
Example #19
Source File: test_frequencies.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_to_offset_invalid(self): # GH 13930 with tm.assert_raises_regex(ValueError, 'Invalid frequency: U1'): frequencies.to_offset('U1') with tm.assert_raises_regex(ValueError, 'Invalid frequency: -U'): frequencies.to_offset('-U') with tm.assert_raises_regex(ValueError, 'Invalid frequency: 3U1'): frequencies.to_offset('3U1') with tm.assert_raises_regex(ValueError, 'Invalid frequency: -2-3U'): frequencies.to_offset('-2-3U') with tm.assert_raises_regex(ValueError, 'Invalid frequency: -2D:3H'): frequencies.to_offset('-2D:3H') with tm.assert_raises_regex(ValueError, 'Invalid frequency: 1.5.0S'): frequencies.to_offset('1.5.0S') # split offsets with spaces are valid assert frequencies.to_offset('2D 3H') == offsets.Hour(51) assert frequencies.to_offset('2 D3 H') == offsets.Hour(51) assert frequencies.to_offset('2 D 3 H') == offsets.Hour(51) assert frequencies.to_offset(' 2 D 3 H ') == offsets.Hour(51) assert frequencies.to_offset(' H ') == offsets.Hour() assert frequencies.to_offset(' 3 H ') == offsets.Hour(3) # special cases assert frequencies.to_offset('2SMS-15') == offsets.SemiMonthBegin(2) with tm.assert_raises_regex(ValueError, 'Invalid frequency: 2SMS-15-15'): frequencies.to_offset('2SMS-15-15') with tm.assert_raises_regex(ValueError, 'Invalid frequency: 2SMS-15D'): frequencies.to_offset('2SMS-15D')
Example #20
Source File: test_ticks.py From coffeegrindsize with MIT License | 5 votes |
def test_apply_ticks(): result = offsets.Hour(3).apply(offsets.Hour(4)) exp = offsets.Hour(7) assert (result == exp)
Example #21
Source File: test_ticks.py From coffeegrindsize with MIT License | 5 votes |
def test_Hour(): assert_offset_equal(Hour(), datetime(2010, 1, 1), datetime(2010, 1, 1, 1)) assert_offset_equal(Hour(-1), datetime(2010, 1, 1, 1), datetime(2010, 1, 1)) assert_offset_equal(2 * Hour(), datetime(2010, 1, 1), datetime(2010, 1, 1, 2)) assert_offset_equal(-1 * Hour(), datetime(2010, 1, 1, 1), datetime(2010, 1, 1)) assert Hour(3) + Hour(2) == Hour(5) assert Hour(3) - Hour(2) == Hour() assert Hour(4) != Hour(1)
Example #22
Source File: test_frequencies.py From coffeegrindsize with MIT License | 5 votes |
def test_to_offset_invalid(self): # GH 13930 with pytest.raises(ValueError, match='Invalid frequency: U1'): frequencies.to_offset('U1') with pytest.raises(ValueError, match='Invalid frequency: -U'): frequencies.to_offset('-U') with pytest.raises(ValueError, match='Invalid frequency: 3U1'): frequencies.to_offset('3U1') with pytest.raises(ValueError, match='Invalid frequency: -2-3U'): frequencies.to_offset('-2-3U') with pytest.raises(ValueError, match='Invalid frequency: -2D:3H'): frequencies.to_offset('-2D:3H') with pytest.raises(ValueError, match='Invalid frequency: 1.5.0S'): frequencies.to_offset('1.5.0S') # split offsets with spaces are valid assert frequencies.to_offset('2D 3H') == offsets.Hour(51) assert frequencies.to_offset('2 D3 H') == offsets.Hour(51) assert frequencies.to_offset('2 D 3 H') == offsets.Hour(51) assert frequencies.to_offset(' 2 D 3 H ') == offsets.Hour(51) assert frequencies.to_offset(' H ') == offsets.Hour() assert frequencies.to_offset(' 3 H ') == offsets.Hour(3) # special cases assert frequencies.to_offset('2SMS-15') == offsets.SemiMonthBegin(2) with pytest.raises(ValueError, match='Invalid frequency: 2SMS-15-15'): frequencies.to_offset('2SMS-15-15') with pytest.raises(ValueError, match='Invalid frequency: 2SMS-15D'): frequencies.to_offset('2SMS-15D')
Example #23
Source File: test_frequencies.py From coffeegrindsize with MIT License | 5 votes |
def test_frequency_misc(self): assert (resolution.get_freq_group('T') == FreqGroup.FR_MIN) code, stride = get_freq_code(offsets.Hour()) assert code == FreqGroup.FR_HR code, stride = get_freq_code((5, 'T')) assert code == FreqGroup.FR_MIN assert stride == 5 offset = offsets.Hour() result = frequencies.to_offset(offset) assert result == offset result = frequencies.to_offset((5, 'T')) expected = offsets.Minute(5) assert result == expected with pytest.raises(ValueError, match='Invalid frequency'): get_freq_code((5, 'baz')) with pytest.raises(ValueError, match='Invalid frequency'): frequencies.to_offset('100foo') with pytest.raises(ValueError, match='Could not evaluate'): frequencies.to_offset(('', ''))
Example #24
Source File: test_resample.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_str(self): r = self.series.resample('H') assert ('DatetimeIndexResampler [freq=<Hour>, axis=0, closed=left, ' 'label=left, convention=start, base=0]' in str(r))
Example #25
Source File: test_resample.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_resample_reresample(self): dti = DatetimeIndex(start=datetime(2005, 1, 1), end=datetime(2005, 1, 10), freq='D') s = Series(np.random.rand(len(dti)), dti) bs = s.resample('B', closed='right', label='right').mean() result = bs.resample('8H').mean() assert len(result) == 22 assert isinstance(result.index.freq, offsets.DateOffset) assert result.index.freq == offsets.Hour(8)
Example #26
Source File: test_resample.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_repr(self): # GH18203 result = repr(TimeGrouper(key='A', freq='H')) expected = ("TimeGrouper(key='A', freq=<Hour>, axis=0, sort=True, " "closed='left', label='left', how='mean', " "convention='e', base=0)") assert result == expected
Example #27
Source File: test_ticks.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_apply_ticks(): result = offsets.Hour(3).apply(offsets.Hour(4)) exp = offsets.Hour(7) assert (result == exp)
Example #28
Source File: test_ticks.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_Hour(): assert_offset_equal(Hour(), datetime(2010, 1, 1), datetime(2010, 1, 1, 1)) assert_offset_equal(Hour(-1), datetime(2010, 1, 1, 1), datetime(2010, 1, 1)) assert_offset_equal(2 * Hour(), datetime(2010, 1, 1), datetime(2010, 1, 1, 2)) assert_offset_equal(-1 * Hour(), datetime(2010, 1, 1, 1), datetime(2010, 1, 1)) assert Hour(3) + Hour(2) == Hour(5) assert Hour(3) - Hour(2) == Hour() assert Hour(4) != Hour(1)
Example #29
Source File: test_frequencies.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_frequency_misc(self): assert (resolution.get_freq_group('T') == frequencies.FreqGroup.FR_MIN) code, stride = frequencies.get_freq_code(offsets.Hour()) assert code == frequencies.FreqGroup.FR_HR code, stride = frequencies.get_freq_code((5, 'T')) assert code == frequencies.FreqGroup.FR_MIN assert stride == 5 offset = offsets.Hour() result = frequencies.to_offset(offset) assert result == offset result = frequencies.to_offset((5, 'T')) expected = offsets.Minute(5) assert result == expected with tm.assert_raises_regex(ValueError, 'Invalid frequency'): frequencies.get_freq_code((5, 'baz')) with tm.assert_raises_regex(ValueError, 'Invalid frequency'): frequencies.to_offset('100foo') with tm.assert_raises_regex(ValueError, 'Could not evaluate'): frequencies.to_offset(('', ''))
Example #30
Source File: test_resample.py From Computable with MIT License | 5 votes |
def test_resample_reresample(self): dti = DatetimeIndex( start=datetime(2005, 1, 1), end=datetime(2005, 1, 10), freq='D') s = Series(np.random.rand(len(dti)), dti) bs = s.resample('B', closed='right', label='right') result = bs.resample('8H') self.assertEquals(len(result), 22) tm.assert_isinstance(result.index.freq, offsets.DateOffset) self.assert_(result.index.freq == offsets.Hour(8))