Python pandas.bdate_range() Examples
The following are 30
code examples of pandas.bdate_range().
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
, or try the search function
.
Example #1
Source File: test_indexing.py From recruit with Apache License 2.0 | 6 votes |
def test_dti_business_getitem(self): rng = pd.bdate_range(START, END) smaller = rng[:5] exp = DatetimeIndex(rng.view(np.ndarray)[:5]) tm.assert_index_equal(smaller, exp) assert smaller.freq == rng.freq sliced = rng[::5] assert sliced.freq == BDay() * 5 fancy_indexed = rng[[4, 3, 2, 1, 0]] assert len(fancy_indexed) == 5 assert isinstance(fancy_indexed, DatetimeIndex) assert fancy_indexed.freq is None # 32-bit vs. 64-bit platforms assert rng[4] == rng[np.int_(4)]
Example #2
Source File: test_indexing.py From recruit with Apache License 2.0 | 6 votes |
def test_dti_custom_getitem(self): rng = pd.bdate_range(START, END, freq='C') smaller = rng[:5] exp = DatetimeIndex(rng.view(np.ndarray)[:5]) tm.assert_index_equal(smaller, exp) assert smaller.freq == rng.freq sliced = rng[::5] assert sliced.freq == CDay() * 5 fancy_indexed = rng[[4, 3, 2, 1, 0]] assert len(fancy_indexed) == 5 assert isinstance(fancy_indexed, DatetimeIndex) assert fancy_indexed.freq is None # 32-bit vs. 64-bit platforms assert rng[4] == rng[np.int_(4)]
Example #3
Source File: generate_legacy_pickles.py From Computable with MIT License | 6 votes |
def _create_sp_tsseries(): import numpy as np from pandas import bdate_range, SparseTimeSeries nan = np.nan # nan-based arr = np.arange(15, dtype=np.float64) index = np.arange(15) arr[7:12] = nan arr[-1:] = nan date_index = bdate_range('1/1/2011', periods=len(index)) bseries = SparseTimeSeries(arr, index=date_index, kind='block') bseries.name = 'btsseries' return bseries
Example #4
Source File: test_resample.py From vnpy_crypto with MIT License | 6 votes |
def test_resample_bms_2752(self): # GH2753 foo = Series(index=pd.bdate_range('20000101', '20000201')) res1 = foo.resample("BMS").mean() res2 = foo.resample("BMS").mean().resample("B").mean() assert res1.index[0] == Timestamp('20000103') assert res1.index[0] == res2.index[0] # def test_monthly_convention_span(self): # rng = period_range('2000-01', periods=3, freq='M') # ts = Series(np.arange(3), index=rng) # # hacky way to get same thing # exp_index = period_range('2000-01-01', '2000-03-31', freq='D') # expected = ts.asfreq('D', how='end').reindex(exp_index) # expected = expected.fillna(method='bfill') # result = ts.resample('D', convention='span').mean() # assert_series_equal(result, expected)
Example #5
Source File: test_moments.py From Computable with MIT License | 6 votes |
def test_legacy_time_rule_arg(self): # suppress deprecation warnings sys.stderr = StringIO() rng = bdate_range('1/1/2000', periods=20) ts = Series(np.random.randn(20), index=rng) ts = ts.take(np.random.permutation(len(ts))[:12]).sort_index() try: result = mom.rolling_mean(ts, 1, min_periods=1, freq='B') expected = mom.rolling_mean(ts, 1, min_periods=1, time_rule='WEEKDAY') tm.assert_series_equal(result, expected) result = mom.ewma(ts, span=5, freq='B') expected = mom.ewma(ts, span=5, time_rule='WEEKDAY') tm.assert_series_equal(result, expected) finally: sys.stderr = sys.__stderr__
Example #6
Source File: test_resample.py From Computable with MIT License | 6 votes |
def test_resample_bms_2752(self): # GH2753 foo = pd.Series(index=pd.bdate_range('20000101','20000201')) res1 = foo.resample("BMS") res2 = foo.resample("BMS").resample("B") self.assertEqual(res1.index[0], Timestamp('20000103')) self.assertEqual(res1.index[0], res2.index[0]) # def test_monthly_convention_span(self): # rng = period_range('2000-01', periods=3, freq='M') # ts = Series(np.arange(3), index=rng) # # hacky way to get same thing # exp_index = period_range('2000-01-01', '2000-03-31', freq='D') # expected = ts.asfreq('D', how='end').reindex(exp_index) # expected = expected.fillna(method='bfill') # result = ts.resample('D', convention='span') # assert_series_equal(result, expected)
Example #7
Source File: test_apply.py From recruit with Apache License 2.0 | 6 votes |
def test_apply_series_to_frame(): def f(piece): with np.errstate(invalid='ignore'): logged = np.log(piece) return DataFrame({'value': piece, 'demeaned': piece - piece.mean(), 'logged': logged}) dr = bdate_range('1/1/2000', periods=100) ts = Series(np.random.randn(100), index=dr) grouped = ts.groupby(lambda x: x.month) result = grouped.apply(f) assert isinstance(result, DataFrame) tm.assert_index_equal(result.index, ts.index)
Example #8
Source File: test_apply.py From vnpy_crypto with MIT License | 6 votes |
def test_apply_series_to_frame(): def f(piece): with np.errstate(invalid='ignore'): logged = np.log(piece) return DataFrame({'value': piece, 'demeaned': piece - piece.mean(), 'logged': logged}) dr = bdate_range('1/1/2000', periods=100) ts = Series(np.random.randn(100), index=dr) grouped = ts.groupby(lambda x: x.month) result = grouped.apply(f) assert isinstance(result, DataFrame) tm.assert_index_equal(result.index, ts.index)
Example #9
Source File: test_period_index.py From recruit with Apache License 2.0 | 6 votes |
def test_resample_bms_2752(self): # GH2753 foo = Series(index=pd.bdate_range('20000101', '20000201')) res1 = foo.resample("BMS").mean() res2 = foo.resample("BMS").mean().resample("B").mean() assert res1.index[0] == Timestamp('20000103') assert res1.index[0] == res2.index[0] # def test_monthly_convention_span(self): # rng = period_range('2000-01', periods=3, freq='M') # ts = Series(np.arange(3), index=rng) # # hacky way to get same thing # exp_index = period_range('2000-01-01', '2000-03-31', freq='D') # expected = ts.asfreq('D', how='end').reindex(exp_index) # expected = expected.fillna(method='bfill') # result = ts.resample('D', convention='span').mean() # assert_series_equal(result, expected)
Example #10
Source File: test_indexing.py From vnpy_crypto with MIT License | 6 votes |
def test_dti_custom_getitem(self): rng = pd.bdate_range(START, END, freq='C') smaller = rng[:5] exp = DatetimeIndex(rng.view(np.ndarray)[:5]) tm.assert_index_equal(smaller, exp) assert smaller.freq == rng.freq sliced = rng[::5] assert sliced.freq == CDay() * 5 fancy_indexed = rng[[4, 3, 2, 1, 0]] assert len(fancy_indexed) == 5 assert isinstance(fancy_indexed, DatetimeIndex) assert fancy_indexed.freq is None # 32-bit vs. 64-bit platforms assert rng[4] == rng[np.int_(4)]
Example #11
Source File: test_sparse.py From Computable with MIT License | 6 votes |
def test_shift(self): series = SparseSeries([nan, 1., 2., 3., nan, nan], index=np.arange(6)) shifted = series.shift(0) self.assert_(shifted is not series) assert_sp_series_equal(shifted, series) f = lambda s: s.shift(1) _dense_series_compare(series, f) f = lambda s: s.shift(-2) _dense_series_compare(series, f) series = SparseSeries([nan, 1., 2., 3., nan, nan], index=bdate_range('1/1/2000', periods=6)) f = lambda s: s.shift(2, freq='B') _dense_series_compare(series, f) f = lambda s: s.shift(2, freq=datetools.bday) _dense_series_compare(series, f)
Example #12
Source File: test_formats.py From vnpy_crypto with MIT License | 5 votes |
def test_dti_custom_business_summary_pytz(self): pd.bdate_range('1/1/2005', '1/1/2009', freq='C', tz=pytz.utc)._summary()
Example #13
Source File: test_formats.py From vnpy_crypto with MIT License | 5 votes |
def test_dti_business_summary(self): rng = pd.bdate_range(datetime(2009, 1, 1), datetime(2010, 1, 1)) rng._summary() rng[2:2]._summary()
Example #14
Source File: test_formats.py From vnpy_crypto with MIT License | 5 votes |
def test_dti_custom_business_summary_dateutil(self): pd.bdate_range('1/1/2005', '1/1/2009', freq='C', tz=dateutil.tz.tzutc())._summary()
Example #15
Source File: test_series.py From vnpy_crypto with MIT License | 5 votes |
def test_custom_business_day_freq(self): # GH7222 from pandas.tseries.offsets import CustomBusinessDay s = Series(range(100, 121), index=pd.bdate_range( start='2014-05-01', end='2014-06-01', freq=CustomBusinessDay(holidays=['2014-05-26']))) _check_plot_works(s.plot)
Example #16
Source File: test_sparse.py From Computable with MIT License | 5 votes |
def test_reindex_fill_value(self): rng = bdate_range('20110110', periods=20) result = self.zframe.reindex(rng, fill_value=0) expected = self.zframe.reindex(rng).fillna(0) assert_sp_frame_equal(result, expected)
Example #17
Source File: test_sparse.py From Computable with MIT License | 5 votes |
def panel_data3(): index = bdate_range('1/1/2011', periods=10).shift(-2) return DataFrame({ 'A': [nan, nan, nan, 0, 1, 2, 3, 4, 5, 6], 'B': [0, 1, 2, 3, 4, 5, 6, nan, nan, nan], 'C': [0, 1, 2, nan, nan, nan, 3, 4, 5, 6], 'D': [nan, 0, 1, nan, 2, 3, 4, 5, 6, nan] }, index=index)
Example #18
Source File: test_sparse.py From Computable with MIT License | 5 votes |
def panel_data2(): index = bdate_range('1/1/2011', periods=9) return DataFrame({ 'A': [nan, nan, nan, 0, 1, 2, 3, 4, 5], 'B': [0, 1, 2, 3, 4, 5, nan, nan, nan], 'C': [0, 1, 2, nan, nan, nan, 3, 4, 5], 'D': [nan, 0, 1, nan, 2, 3, 4, 5, nan] }, index=index)
Example #19
Source File: test_moments.py From Computable with MIT License | 5 votes |
def setUp(self): arr = randn(N) arr[self._nan_locs] = np.NaN self.arr = arr self.rng = bdate_range(datetime(2009, 1, 1), periods=N) self.series = Series(arr.copy(), index=self.rng) self.frame = DataFrame(randn(N, K), index=self.rng, columns=np.arange(K))
Example #20
Source File: test_formats.py From vnpy_crypto with MIT License | 5 votes |
def test_dti_custom_business_repr(self): # only really care that it works repr(pd.bdate_range(datetime(2009, 1, 1), datetime(2010, 1, 1), freq='C'))
Example #21
Source File: test_formats.py From vnpy_crypto with MIT License | 5 votes |
def test_dti_business_summary_dateutil(self): pd.bdate_range('1/1/2005', '1/1/2009', tz=dateutil.tz.tzutc())._summary()
Example #22
Source File: test_formats.py From vnpy_crypto with MIT License | 5 votes |
def test_dti_business_summary_pytz(self): pd.bdate_range('1/1/2005', '1/1/2009', tz=pytz.utc)._summary()
Example #23
Source File: Fetch_Data_Stock_HK_Daily.py From StockRecommendSystem with MIT License | 5 votes |
def judgeOpenDaysInRange(from_date, to_date): holidays=["2017-01-01", "2017-01-02", "2017-01-27", "2017-01-28", "2017-01-29", "2017-01-30", "2017-01-31", "2017-02-01", "2017-02-02", "2017-04-02", "2017-04-03", "2017-04-04", "2017-05-01", "2017-05-28", "2017-05-29", "2017-05-30", "2017-10-01", "2017-10-02", "2017-10-03", "2017-10-04", "2017-10-05","2017-10-06","2017-10-07","2017-10-08"] #holidays = cal.holidays(from_date, to_date) duedays = pd.bdate_range(from_date, to_date) df = pd.DataFrame() df['Date'] = duedays df['Holiday'] = duedays.isin(holidays) opendays = df[df['Holiday'] == False] return opendays
Example #24
Source File: test_formats.py From vnpy_crypto with MIT License | 5 votes |
def test_dti_business_repr(self): # only really care that it works repr(pd.bdate_range(datetime(2009, 1, 1), datetime(2010, 1, 1)))
Example #25
Source File: test_date_range.py From vnpy_crypto with MIT License | 5 votes |
def test_cdaterange_weekmask_and_holidays(self): result = bdate_range('2013-05-01', periods=3, freq='C', weekmask='Sun Mon Tue Wed Thu', holidays=['2013-05-01']) expected = DatetimeIndex(['2013-05-02', '2013-05-05', '2013-05-06']) tm.assert_index_equal(result, expected) # raise with non-custom freq msg = ('a custom frequency string is required when holidays or ' 'weekmask are passed, got frequency B') with tm.assert_raises_regex(ValueError, msg): bdate_range('2013-05-01', periods=3, weekmask='Sun Mon Tue Wed Thu', holidays=['2013-05-01'])
Example #26
Source File: test_date_range.py From vnpy_crypto with MIT License | 5 votes |
def test_cdaterange_holidays(self): result = bdate_range('2013-05-01', periods=3, freq='C', holidays=['2013-05-01']) expected = DatetimeIndex(['2013-05-02', '2013-05-03', '2013-05-06']) tm.assert_index_equal(result, expected) # raise with non-custom freq msg = ('a custom frequency string is required when holidays or ' 'weekmask are passed, got frequency B') with tm.assert_raises_regex(ValueError, msg): bdate_range('2013-05-01', periods=3, holidays=['2013-05-01'])
Example #27
Source File: test_date_range.py From vnpy_crypto with MIT License | 5 votes |
def test_cdaterange_weekmask(self): result = bdate_range('2013-05-01', periods=3, freq='C', weekmask='Sun Mon Tue Wed Thu') expected = DatetimeIndex(['2013-05-01', '2013-05-02', '2013-05-05']) tm.assert_index_equal(result, expected) # raise with non-custom freq msg = ('a custom frequency string is required when holidays or ' 'weekmask are passed, got frequency B') with tm.assert_raises_regex(ValueError, msg): bdate_range('2013-05-01', periods=3, weekmask='Sun Mon Tue Wed Thu')
Example #28
Source File: test_date_range.py From vnpy_crypto with MIT License | 5 votes |
def test_cdaterange(self): result = bdate_range('2013-05-01', periods=3, freq='C') expected = DatetimeIndex(['2013-05-01', '2013-05-02', '2013-05-03']) tm.assert_index_equal(result, expected)
Example #29
Source File: test_date_range.py From vnpy_crypto with MIT License | 5 votes |
def test_daterange_bug_456(self): # GH #456 rng1 = bdate_range('12/5/2011', '12/5/2011', freq='C') rng2 = bdate_range('12/2/2011', '12/5/2011', freq='C') rng2.freq = CDay() result = rng1.union(rng2) assert isinstance(result, DatetimeIndex)
Example #30
Source File: test_date_range.py From vnpy_crypto with MIT License | 5 votes |
def test_constructor(self): bdate_range(START, END, freq=CDay()) bdate_range(START, periods=20, freq=CDay()) bdate_range(end=START, periods=20, freq=CDay()) msg = 'periods must be a number, got C' with tm.assert_raises_regex(TypeError, msg): date_range('2011-1-1', '2012-1-1', 'C') with tm.assert_raises_regex(TypeError, msg): bdate_range('2011-1-1', '2012-1-1', 'C')