Python numpy.busdaycalendar() Examples
The following are 30
code examples of numpy.busdaycalendar().
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
numpy
, or try the search function
.
Example #1
Source File: test_datetime.py From recruit with Apache License 2.0 | 6 votes |
def test_datetime_busday_holidays_count(self): holidays = ['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24', '2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17', '2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30', '2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10'] bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays) # Validate against busday_offset broadcast against # a range of offsets dates = np.busday_offset('2011-01-01', np.arange(366), roll='forward', busdaycal=bdd) assert_equal(np.busday_count('2011-01-01', dates, busdaycal=bdd), np.arange(366)) # Returns negative value when reversed assert_equal(np.busday_count(dates, '2011-01-01', busdaycal=bdd), -np.arange(366)) dates = np.busday_offset('2011-12-31', -np.arange(366), roll='forward', busdaycal=bdd) assert_equal(np.busday_count(dates, '2011-12-31', busdaycal=bdd), np.arange(366)) # Returns negative value when reversed assert_equal(np.busday_count('2011-12-31', dates, busdaycal=bdd), -np.arange(366)) # Can't supply both a weekmask/holidays and busdaycal assert_raises(ValueError, np.busday_offset, '2012-01-03', '2012-02-03', weekmask='1111100', busdaycal=bdd) assert_raises(ValueError, np.busday_offset, '2012-01-03', '2012-02-03', holidays=holidays, busdaycal=bdd) # Number of Mondays in March 2011 assert_equal(np.busday_count('2011-03', '2011-04', weekmask='Mon'), 4) # Returns negative value when reversed assert_equal(np.busday_count('2011-04', '2011-03', weekmask='Mon'), -4)
Example #2
Source File: test_datetime.py From keras-lambda with MIT License | 6 votes |
def test_datetime_is_busday(self): holidays = ['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24', '2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17', '2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30', '2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10', 'NaT'] bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays) # Weekend/weekday tests assert_equal(np.is_busday('2011-01-01'), False) assert_equal(np.is_busday('2011-01-02'), False) assert_equal(np.is_busday('2011-01-03'), True) # All the holidays are not business days assert_equal(np.is_busday(holidays, busdaycal=bdd), np.zeros(len(holidays), dtype='?'))
Example #3
Source File: test_datetime.py From twitter-stock-recommendation with MIT License | 6 votes |
def test_datetime_is_busday(self): holidays = ['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24', '2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17', '2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30', '2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10', 'NaT'] bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays) # Weekend/weekday tests assert_equal(np.is_busday('2011-01-01'), False) assert_equal(np.is_busday('2011-01-02'), False) assert_equal(np.is_busday('2011-01-03'), True) # All the holidays are not business days assert_equal(np.is_busday(holidays, busdaycal=bdd), np.zeros(len(holidays), dtype='?'))
Example #4
Source File: test_datetime.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 6 votes |
def test_datetime_is_busday(self): holidays = ['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24', '2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17', '2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30', '2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10', 'NaT'] bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays) # Weekend/weekday tests assert_equal(np.is_busday('2011-01-01'), False) assert_equal(np.is_busday('2011-01-02'), False) assert_equal(np.is_busday('2011-01-03'), True) # All the holidays are not business days assert_equal(np.is_busday(holidays, busdaycal=bdd), np.zeros(len(holidays), dtype='?'))
Example #5
Source File: test_datetime.py From coffeegrindsize with MIT License | 6 votes |
def test_datetime_is_busday(self): holidays = ['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24', '2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17', '2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30', '2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10', 'NaT'] bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays) # Weekend/weekday tests assert_equal(np.is_busday('2011-01-01'), False) assert_equal(np.is_busday('2011-01-02'), False) assert_equal(np.is_busday('2011-01-03'), True) # All the holidays are not business days assert_equal(np.is_busday(holidays, busdaycal=bdd), np.zeros(len(holidays), dtype='?'))
Example #6
Source File: test_datetime.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def test_datetime_is_busday(self): holidays = ['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24', '2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17', '2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30', '2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10', 'NaT'] bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays) # Weekend/weekday tests assert_equal(np.is_busday('2011-01-01'), False) assert_equal(np.is_busday('2011-01-02'), False) assert_equal(np.is_busday('2011-01-03'), True) # All the holidays are not business days assert_equal(np.is_busday(holidays, busdaycal=bdd), np.zeros(len(holidays), dtype='?'))
Example #7
Source File: test_datetime.py From ImageFusion with MIT License | 6 votes |
def test_datetime_is_busday(self): holidays=['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24', '2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17', '2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30', '2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10', 'NaT'] bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays) # Weekend/weekday tests assert_equal(np.is_busday('2011-01-01'), False) assert_equal(np.is_busday('2011-01-02'), False) assert_equal(np.is_busday('2011-01-03'), True) # All the holidays are not business days assert_equal(np.is_busday(holidays, busdaycal=bdd), np.zeros(len(holidays), dtype='?'))
Example #8
Source File: test_datetime.py From mxnet-lambda with Apache License 2.0 | 6 votes |
def test_datetime_is_busday(self): holidays = ['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24', '2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17', '2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30', '2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10', 'NaT'] bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays) # Weekend/weekday tests assert_equal(np.is_busday('2011-01-01'), False) assert_equal(np.is_busday('2011-01-02'), False) assert_equal(np.is_busday('2011-01-03'), True) # All the holidays are not business days assert_equal(np.is_busday(holidays, busdaycal=bdd), np.zeros(len(holidays), dtype='?'))
Example #9
Source File: test_datetime.py From pySINDy with MIT License | 6 votes |
def test_datetime_is_busday(self): holidays = ['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24', '2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17', '2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30', '2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10', 'NaT'] bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays) # Weekend/weekday tests assert_equal(np.is_busday('2011-01-01'), False) assert_equal(np.is_busday('2011-01-02'), False) assert_equal(np.is_busday('2011-01-03'), True) # All the holidays are not business days assert_equal(np.is_busday(holidays, busdaycal=bdd), np.zeros(len(holidays), dtype='?'))
Example #10
Source File: test_datetime.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_datetime_is_busday(self): holidays = ['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24', '2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17', '2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30', '2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10', 'NaT'] bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays) # Weekend/weekday tests assert_equal(np.is_busday('2011-01-01'), False) assert_equal(np.is_busday('2011-01-02'), False) assert_equal(np.is_busday('2011-01-03'), True) # All the holidays are not business days assert_equal(np.is_busday(holidays, busdaycal=bdd), np.zeros(len(holidays), dtype='?'))
Example #11
Source File: test_datetime.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_datetime_is_busday(self): holidays = ['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24', '2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17', '2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30', '2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10', 'NaT'] bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays) # Weekend/weekday tests assert_equal(np.is_busday('2011-01-01'), False) assert_equal(np.is_busday('2011-01-02'), False) assert_equal(np.is_busday('2011-01-03'), True) # All the holidays are not business days assert_equal(np.is_busday(holidays, busdaycal=bdd), np.zeros(len(holidays), dtype='?'))
Example #12
Source File: test_datetime.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def test_datetime_is_busday(self): holidays = ['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24', '2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17', '2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30', '2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10', 'NaT'] bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays) # Weekend/weekday tests assert_equal(np.is_busday('2011-01-01'), False) assert_equal(np.is_busday('2011-01-02'), False) assert_equal(np.is_busday('2011-01-03'), True) # All the holidays are not business days assert_equal(np.is_busday(holidays, busdaycal=bdd), np.zeros(len(holidays), dtype='?'))
Example #13
Source File: test_datetime.py From recruit with Apache License 2.0 | 6 votes |
def test_datetime_is_busday(self): holidays = ['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24', '2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17', '2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30', '2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10', 'NaT'] bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays) # Weekend/weekday tests assert_equal(np.is_busday('2011-01-01'), False) assert_equal(np.is_busday('2011-01-02'), False) assert_equal(np.is_busday('2011-01-03'), True) # All the holidays are not business days assert_equal(np.is_busday(holidays, busdaycal=bdd), np.zeros(len(holidays), dtype='?'))
Example #14
Source File: test_datetime.py From Computable with MIT License | 6 votes |
def test_datetime_is_busday(self): holidays=['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24', '2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17', '2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30', '2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10', 'NaT'] bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays) # Weekend/weekday tests assert_equal(np.is_busday('2011-01-01'), False) assert_equal(np.is_busday('2011-01-02'), False) assert_equal(np.is_busday('2011-01-03'), True) # All the holidays are not business days assert_equal(np.is_busday(holidays, busdaycal=bdd), np.zeros(len(holidays), dtype='?'))
Example #15
Source File: test_datetime.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def test_datetime_is_busday(self): holidays = ['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24', '2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17', '2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30', '2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10', 'NaT'] bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays) # Weekend/weekday tests assert_equal(np.is_busday('2011-01-01'), False) assert_equal(np.is_busday('2011-01-02'), False) assert_equal(np.is_busday('2011-01-03'), True) # All the holidays are not business days assert_equal(np.is_busday(holidays, busdaycal=bdd), np.zeros(len(holidays), dtype='?'))
Example #16
Source File: test_datetime.py From vnpy_crypto with MIT License | 6 votes |
def test_datetime_is_busday(self): holidays = ['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24', '2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17', '2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30', '2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10', 'NaT'] bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays) # Weekend/weekday tests assert_equal(np.is_busday('2011-01-01'), False) assert_equal(np.is_busday('2011-01-02'), False) assert_equal(np.is_busday('2011-01-03'), True) # All the holidays are not business days assert_equal(np.is_busday(holidays, busdaycal=bdd), np.zeros(len(holidays), dtype='?'))
Example #17
Source File: test_datetime.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def test_datetime_busdaycalendar(self): # Check that it removes NaT, duplicates, and weekends # and sorts the result. bdd = np.busdaycalendar( holidays=['NaT', '2011-01-17', '2011-03-06', 'NaT', '2011-12-26', '2011-05-30', '2011-01-17']) assert_equal(bdd.holidays, np.array(['2011-01-17', '2011-05-30', '2011-12-26'], dtype='M8')) # Default M-F weekmask assert_equal(bdd.weekmask, np.array([1, 1, 1, 1, 1, 0, 0], dtype='?')) # Check string weekmask with varying whitespace. bdd = np.busdaycalendar(weekmask="Sun TueWed Thu\tFri") assert_equal(bdd.weekmask, np.array([0, 1, 1, 1, 1, 0, 1], dtype='?')) # Check length 7 0/1 string bdd = np.busdaycalendar(weekmask="0011001") assert_equal(bdd.weekmask, np.array([0, 0, 1, 1, 0, 0, 1], dtype='?')) # Check length 7 string weekmask. bdd = np.busdaycalendar(weekmask="Mon Tue") assert_equal(bdd.weekmask, np.array([1, 1, 0, 0, 0, 0, 0], dtype='?')) # All-zeros weekmask should raise assert_raises(ValueError, np.busdaycalendar, weekmask=[0, 0, 0, 0, 0, 0, 0]) # weekday names must be correct case assert_raises(ValueError, np.busdaycalendar, weekmask="satsun") # All-zeros weekmask should raise assert_raises(ValueError, np.busdaycalendar, weekmask="") # Invalid weekday name codes should raise assert_raises(ValueError, np.busdaycalendar, weekmask="Mon Tue We") assert_raises(ValueError, np.busdaycalendar, weekmask="Max") assert_raises(ValueError, np.busdaycalendar, weekmask="Monday Tue")
Example #18
Source File: gscalendar.py From gs-quant with Apache License 2.0 | 5 votes |
def business_day_calendar(self, week_mask: str = None) -> np.busdaycalendar: return self.__business_day_calendars.setdefault(week_mask, np.busdaycalendar( weekmask=week_mask or self.DEFAULT_WEEK_MASK, holidays=tuple(self.holidays)))
Example #19
Source File: offsets.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def _get_calendar(weekmask, holidays, calendar): """Generate busdaycalendar""" if isinstance(calendar, np.busdaycalendar): if not holidays: holidays = tuple(calendar.holidays) elif not isinstance(holidays, tuple): holidays = tuple(holidays) else: # trust that calendar.holidays and holidays are # consistent pass return calendar, holidays if holidays is None: holidays = [] try: holidays = holidays + calendar.holidays().tolist() except AttributeError: pass holidays = [_to_dt64(dt, dtype='datetime64[D]') for dt in holidays] holidays = tuple(sorted(holidays)) kwargs = {'weekmask': weekmask} if holidays: kwargs['holidays'] = holidays busdaycalendar = np.busdaycalendar(**kwargs) return busdaycalendar, holidays
Example #20
Source File: test_datetime.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_datetime_busdaycalendar(self): # Check that it removes NaT, duplicates, and weekends # and sorts the result. bdd = np.busdaycalendar( holidays=['NaT', '2011-01-17', '2011-03-06', 'NaT', '2011-12-26', '2011-05-30', '2011-01-17']) assert_equal(bdd.holidays, np.array(['2011-01-17', '2011-05-30', '2011-12-26'], dtype='M8')) # Default M-F weekmask assert_equal(bdd.weekmask, np.array([1, 1, 1, 1, 1, 0, 0], dtype='?')) # Check string weekmask with varying whitespace. bdd = np.busdaycalendar(weekmask="Sun TueWed Thu\tFri") assert_equal(bdd.weekmask, np.array([0, 1, 1, 1, 1, 0, 1], dtype='?')) # Check length 7 0/1 string bdd = np.busdaycalendar(weekmask="0011001") assert_equal(bdd.weekmask, np.array([0, 0, 1, 1, 0, 0, 1], dtype='?')) # Check length 7 string weekmask. bdd = np.busdaycalendar(weekmask="Mon Tue") assert_equal(bdd.weekmask, np.array([1, 1, 0, 0, 0, 0, 0], dtype='?')) # All-zeros weekmask should raise assert_raises(ValueError, np.busdaycalendar, weekmask=[0, 0, 0, 0, 0, 0, 0]) # weekday names must be correct case assert_raises(ValueError, np.busdaycalendar, weekmask="satsun") # All-zeros weekmask should raise assert_raises(ValueError, np.busdaycalendar, weekmask="") # Invalid weekday name codes should raise assert_raises(ValueError, np.busdaycalendar, weekmask="Mon Tue We") assert_raises(ValueError, np.busdaycalendar, weekmask="Max") assert_raises(ValueError, np.busdaycalendar, weekmask="Monday Tue")
Example #21
Source File: test_datetime.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_datetime_busday_holidays_count(self): holidays = ['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24', '2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17', '2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30', '2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10'] bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays) # Validate against busday_offset broadcast against # a range of offsets dates = np.busday_offset('2011-01-01', np.arange(366), roll='forward', busdaycal=bdd) assert_equal(np.busday_count('2011-01-01', dates, busdaycal=bdd), np.arange(366)) # Returns negative value when reversed assert_equal(np.busday_count(dates, '2011-01-01', busdaycal=bdd), -np.arange(366)) dates = np.busday_offset('2011-12-31', -np.arange(366), roll='forward', busdaycal=bdd) assert_equal(np.busday_count(dates, '2011-12-31', busdaycal=bdd), np.arange(366)) # Returns negative value when reversed assert_equal(np.busday_count('2011-12-31', dates, busdaycal=bdd), -np.arange(366)) # Can't supply both a weekmask/holidays and busdaycal assert_raises(ValueError, np.busday_offset, '2012-01-03', '2012-02-03', weekmask='1111100', busdaycal=bdd) assert_raises(ValueError, np.busday_offset, '2012-01-03', '2012-02-03', holidays=holidays, busdaycal=bdd) # Number of Mondays in March 2011 assert_equal(np.busday_count('2011-03', '2011-04', weekmask='Mon'), 4) # Returns negative value when reversed assert_equal(np.busday_count('2011-04', '2011-03', weekmask='Mon'), -4)
Example #22
Source File: offsets.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def _get_calendar(weekmask, holidays, calendar): """Generate busdaycalendar""" if isinstance(calendar, np.busdaycalendar): if not holidays: holidays = tuple(calendar.holidays) elif not isinstance(holidays, tuple): holidays = tuple(holidays) else: # trust that calendar.holidays and holidays are # consistent pass return calendar, holidays if holidays is None: holidays = [] try: holidays = holidays + calendar.holidays().tolist() except AttributeError: pass holidays = [_to_dt64(dt, dtype='datetime64[D]') for dt in holidays] holidays = tuple(sorted(holidays)) kwargs = {'weekmask': weekmask} if holidays: kwargs['holidays'] = holidays busdaycalendar = np.busdaycalendar(**kwargs) return busdaycalendar, holidays
Example #23
Source File: test_datetime.py From coffeegrindsize with MIT License | 5 votes |
def test_datetime_busdaycalendar(self): # Check that it removes NaT, duplicates, and weekends # and sorts the result. bdd = np.busdaycalendar( holidays=['NaT', '2011-01-17', '2011-03-06', 'NaT', '2011-12-26', '2011-05-30', '2011-01-17']) assert_equal(bdd.holidays, np.array(['2011-01-17', '2011-05-30', '2011-12-26'], dtype='M8')) # Default M-F weekmask assert_equal(bdd.weekmask, np.array([1, 1, 1, 1, 1, 0, 0], dtype='?')) # Check string weekmask with varying whitespace. bdd = np.busdaycalendar(weekmask="Sun TueWed Thu\tFri") assert_equal(bdd.weekmask, np.array([0, 1, 1, 1, 1, 0, 1], dtype='?')) # Check length 7 0/1 string bdd = np.busdaycalendar(weekmask="0011001") assert_equal(bdd.weekmask, np.array([0, 0, 1, 1, 0, 0, 1], dtype='?')) # Check length 7 string weekmask. bdd = np.busdaycalendar(weekmask="Mon Tue") assert_equal(bdd.weekmask, np.array([1, 1, 0, 0, 0, 0, 0], dtype='?')) # All-zeros weekmask should raise assert_raises(ValueError, np.busdaycalendar, weekmask=[0, 0, 0, 0, 0, 0, 0]) # weekday names must be correct case assert_raises(ValueError, np.busdaycalendar, weekmask="satsun") # All-zeros weekmask should raise assert_raises(ValueError, np.busdaycalendar, weekmask="") # Invalid weekday name codes should raise assert_raises(ValueError, np.busdaycalendar, weekmask="Mon Tue We") assert_raises(ValueError, np.busdaycalendar, weekmask="Max") assert_raises(ValueError, np.busdaycalendar, weekmask="Monday Tue")
Example #24
Source File: test_datetime.py From coffeegrindsize with MIT License | 5 votes |
def test_datetime_busday_holidays_count(self): holidays = ['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24', '2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17', '2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30', '2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10'] bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays) # Validate against busday_offset broadcast against # a range of offsets dates = np.busday_offset('2011-01-01', np.arange(366), roll='forward', busdaycal=bdd) assert_equal(np.busday_count('2011-01-01', dates, busdaycal=bdd), np.arange(366)) # Returns negative value when reversed assert_equal(np.busday_count(dates, '2011-01-01', busdaycal=bdd), -np.arange(366)) dates = np.busday_offset('2011-12-31', -np.arange(366), roll='forward', busdaycal=bdd) assert_equal(np.busday_count(dates, '2011-12-31', busdaycal=bdd), np.arange(366)) # Returns negative value when reversed assert_equal(np.busday_count('2011-12-31', dates, busdaycal=bdd), -np.arange(366)) # Can't supply both a weekmask/holidays and busdaycal assert_raises(ValueError, np.busday_offset, '2012-01-03', '2012-02-03', weekmask='1111100', busdaycal=bdd) assert_raises(ValueError, np.busday_offset, '2012-01-03', '2012-02-03', holidays=holidays, busdaycal=bdd) # Number of Mondays in March 2011 assert_equal(np.busday_count('2011-03', '2011-04', weekmask='Mon'), 4) # Returns negative value when reversed assert_equal(np.busday_count('2011-04', '2011-03', weekmask='Mon'), -4)
Example #25
Source File: test_datetime.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def test_datetime_busday_holidays_count(self): holidays = ['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24', '2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17', '2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30', '2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10'] bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays) # Validate against busday_offset broadcast against # a range of offsets dates = np.busday_offset('2011-01-01', np.arange(366), roll='forward', busdaycal=bdd) assert_equal(np.busday_count('2011-01-01', dates, busdaycal=bdd), np.arange(366)) # Returns negative value when reversed assert_equal(np.busday_count(dates, '2011-01-01', busdaycal=bdd), -np.arange(366)) dates = np.busday_offset('2011-12-31', -np.arange(366), roll='forward', busdaycal=bdd) assert_equal(np.busday_count(dates, '2011-12-31', busdaycal=bdd), np.arange(366)) # Returns negative value when reversed assert_equal(np.busday_count('2011-12-31', dates, busdaycal=bdd), -np.arange(366)) # Can't supply both a weekmask/holidays and busdaycal assert_raises(ValueError, np.busday_offset, '2012-01-03', '2012-02-03', weekmask='1111100', busdaycal=bdd) assert_raises(ValueError, np.busday_offset, '2012-01-03', '2012-02-03', holidays=holidays, busdaycal=bdd) # Number of Mondays in March 2011 assert_equal(np.busday_count('2011-03', '2011-04', weekmask='Mon'), 4) # Returns negative value when reversed assert_equal(np.busday_count('2011-04', '2011-03', weekmask='Mon'), -4)
Example #26
Source File: test_datetime.py From ImageFusion with MIT License | 5 votes |
def test_datetime_busday_holidays_count(self): holidays=['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24', '2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17', '2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30', '2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10'] bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays) # Validate against busday_offset broadcast against # a range of offsets dates = np.busday_offset('2011-01-01', np.arange(366), roll='forward', busdaycal=bdd) assert_equal(np.busday_count('2011-01-01', dates, busdaycal=bdd), np.arange(366)) # Returns negative value when reversed assert_equal(np.busday_count(dates, '2011-01-01', busdaycal=bdd), -np.arange(366)) dates = np.busday_offset('2011-12-31', -np.arange(366), roll='forward', busdaycal=bdd) assert_equal(np.busday_count(dates, '2011-12-31', busdaycal=bdd), np.arange(366)) # Returns negative value when reversed assert_equal(np.busday_count('2011-12-31', dates, busdaycal=bdd), -np.arange(366)) # Can't supply both a weekmask/holidays and busdaycal assert_raises(ValueError, np.busday_offset, '2012-01-03', '2012-02-03', weekmask='1111100', busdaycal=bdd) assert_raises(ValueError, np.busday_offset, '2012-01-03', '2012-02-03', holidays=holidays, busdaycal=bdd) # Number of Mondays in March 2011 assert_equal(np.busday_count('2011-03', '2011-04', weekmask='Mon'), 4) # Returns negative value when reversed assert_equal(np.busday_count('2011-04', '2011-03', weekmask='Mon'), -4)
Example #27
Source File: test_datetime.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def test_datetime_busday_holidays_count(self): holidays = ['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24', '2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17', '2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30', '2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10'] bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays) # Validate against busday_offset broadcast against # a range of offsets dates = np.busday_offset('2011-01-01', np.arange(366), roll='forward', busdaycal=bdd) assert_equal(np.busday_count('2011-01-01', dates, busdaycal=bdd), np.arange(366)) # Returns negative value when reversed assert_equal(np.busday_count(dates, '2011-01-01', busdaycal=bdd), -np.arange(366)) dates = np.busday_offset('2011-12-31', -np.arange(366), roll='forward', busdaycal=bdd) assert_equal(np.busday_count(dates, '2011-12-31', busdaycal=bdd), np.arange(366)) # Returns negative value when reversed assert_equal(np.busday_count('2011-12-31', dates, busdaycal=bdd), -np.arange(366)) # Can't supply both a weekmask/holidays and busdaycal assert_raises(ValueError, np.busday_offset, '2012-01-03', '2012-02-03', weekmask='1111100', busdaycal=bdd) assert_raises(ValueError, np.busday_offset, '2012-01-03', '2012-02-03', holidays=holidays, busdaycal=bdd) # Number of Mondays in March 2011 assert_equal(np.busday_count('2011-03', '2011-04', weekmask='Mon'), 4) # Returns negative value when reversed assert_equal(np.busday_count('2011-04', '2011-03', weekmask='Mon'), -4)
Example #28
Source File: test_datetime.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def test_datetime_busdaycalendar(self): # Check that it removes NaT, duplicates, and weekends # and sorts the result. bdd = np.busdaycalendar( holidays=['NaT', '2011-01-17', '2011-03-06', 'NaT', '2011-12-26', '2011-05-30', '2011-01-17']) assert_equal(bdd.holidays, np.array(['2011-01-17', '2011-05-30', '2011-12-26'], dtype='M8')) # Default M-F weekmask assert_equal(bdd.weekmask, np.array([1, 1, 1, 1, 1, 0, 0], dtype='?')) # Check string weekmask with varying whitespace. bdd = np.busdaycalendar(weekmask="Sun TueWed Thu\tFri") assert_equal(bdd.weekmask, np.array([0, 1, 1, 1, 1, 0, 1], dtype='?')) # Check length 7 0/1 string bdd = np.busdaycalendar(weekmask="0011001") assert_equal(bdd.weekmask, np.array([0, 0, 1, 1, 0, 0, 1], dtype='?')) # Check length 7 string weekmask. bdd = np.busdaycalendar(weekmask="Mon Tue") assert_equal(bdd.weekmask, np.array([1, 1, 0, 0, 0, 0, 0], dtype='?')) # All-zeros weekmask should raise assert_raises(ValueError, np.busdaycalendar, weekmask=[0, 0, 0, 0, 0, 0, 0]) # weekday names must be correct case assert_raises(ValueError, np.busdaycalendar, weekmask="satsun") # All-zeros weekmask should raise assert_raises(ValueError, np.busdaycalendar, weekmask="") # Invalid weekday name codes should raise assert_raises(ValueError, np.busdaycalendar, weekmask="Mon Tue We") assert_raises(ValueError, np.busdaycalendar, weekmask="Max") assert_raises(ValueError, np.busdaycalendar, weekmask="Monday Tue")
Example #29
Source File: test_datetime.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_datetime_busdaycalendar(self): # Check that it removes NaT, duplicates, and weekends # and sorts the result. bdd = np.busdaycalendar( holidays=['NaT', '2011-01-17', '2011-03-06', 'NaT', '2011-12-26', '2011-05-30', '2011-01-17']) assert_equal(bdd.holidays, np.array(['2011-01-17', '2011-05-30', '2011-12-26'], dtype='M8')) # Default M-F weekmask assert_equal(bdd.weekmask, np.array([1, 1, 1, 1, 1, 0, 0], dtype='?')) # Check string weekmask with varying whitespace. bdd = np.busdaycalendar(weekmask="Sun TueWed Thu\tFri") assert_equal(bdd.weekmask, np.array([0, 1, 1, 1, 1, 0, 1], dtype='?')) # Check length 7 0/1 string bdd = np.busdaycalendar(weekmask="0011001") assert_equal(bdd.weekmask, np.array([0, 0, 1, 1, 0, 0, 1], dtype='?')) # Check length 7 string weekmask. bdd = np.busdaycalendar(weekmask="Mon Tue") assert_equal(bdd.weekmask, np.array([1, 1, 0, 0, 0, 0, 0], dtype='?')) # All-zeros weekmask should raise assert_raises(ValueError, np.busdaycalendar, weekmask=[0, 0, 0, 0, 0, 0, 0]) # weekday names must be correct case assert_raises(ValueError, np.busdaycalendar, weekmask="satsun") # All-zeros weekmask should raise assert_raises(ValueError, np.busdaycalendar, weekmask="") # Invalid weekday name codes should raise assert_raises(ValueError, np.busdaycalendar, weekmask="Mon Tue We") assert_raises(ValueError, np.busdaycalendar, weekmask="Max") assert_raises(ValueError, np.busdaycalendar, weekmask="Monday Tue")
Example #30
Source File: test_datetime.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_datetime_busday_holidays_count(self): holidays = ['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24', '2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17', '2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30', '2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10'] bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays) # Validate against busday_offset broadcast against # a range of offsets dates = np.busday_offset('2011-01-01', np.arange(366), roll='forward', busdaycal=bdd) assert_equal(np.busday_count('2011-01-01', dates, busdaycal=bdd), np.arange(366)) # Returns negative value when reversed assert_equal(np.busday_count(dates, '2011-01-01', busdaycal=bdd), -np.arange(366)) dates = np.busday_offset('2011-12-31', -np.arange(366), roll='forward', busdaycal=bdd) assert_equal(np.busday_count(dates, '2011-12-31', busdaycal=bdd), np.arange(366)) # Returns negative value when reversed assert_equal(np.busday_count('2011-12-31', dates, busdaycal=bdd), -np.arange(366)) # Can't supply both a weekmask/holidays and busdaycal assert_raises(ValueError, np.busday_offset, '2012-01-03', '2012-02-03', weekmask='1111100', busdaycal=bdd) assert_raises(ValueError, np.busday_offset, '2012-01-03', '2012-02-03', holidays=holidays, busdaycal=bdd) # Number of Mondays in March 2011 assert_equal(np.busday_count('2011-03', '2011-04', weekmask='Mon'), 4) # Returns negative value when reversed assert_equal(np.busday_count('2011-04', '2011-03', weekmask='Mon'), -4)