Open antoinecarme opened 2 years ago
next business day
import pandas as pd
>>> pd.bdate_range('2000-1-1', periods=2)
DatetimeIndex(['2000-01-03', '2000-01-04'], dtype='datetime64[ns]', freq='B')
>>> pd.bdate_range('2000-1-2', periods=2)
DatetimeIndex(['2000-01-03', '2000-01-04'], dtype='datetime64[ns]', freq='B')
>>> pd.bdate_range('2000-1-3', periods=2)
DatetimeIndex(['2000-01-03', '2000-01-04'], dtype='datetime64[ns]', freq='B')
>>> pd.bdate_range('2000-1-4', periods=2)
DatetimeIndex(['2000-01-04', '2000-01-05'], dtype='datetime64[ns]', freq='B')
>>> lTwoNextBusinessDays = pd.bdate_range('2000-1-1', periods=2)
>>> lTwoNextBusinessDays[0]
Timestamp('2000-01-03 00:00:00', freq='B')
>>> import pandas as pd
>>> def next_business_day(x):
... lNextTwoBusinessDays = pd.bdate_range(x, periods=2)
... lDays = [d for d in lNextTwoBusinessDays if (d > pd.Timestamp(x))]
... return lDays[0]
...
>>> next_business_day('2000-1-1')
Timestamp('2000-01-03 00:00:00', freq='B')
>>> next_business_day('2000-1-2')
Timestamp('2000-01-03 00:00:00', freq='B')
>>> next_business_day('2000-1-3')
Timestamp('2000-01-04 00:00:00', freq='B')
>>> next_business_day('2000-1-4')
Timestamp('2000-01-05 00:00:00', freq='B')
>>> next_business_day('2000-1-5')
Timestamp('2000-01-06 00:00:00', freq='B')
>>> next_business_day('2000-1-6')
Timestamp('2000-01-07 00:00:00', freq='B')
>>> next_business_day('2000-1-7')
Timestamp('2000-01-10 00:00:00', freq='B')
>>> next_business_day('2000-1-8')
Timestamp('2000-01-10 00:00:00', freq='B')
>>> next_business_day('2000-1-9')
Timestamp('2000-01-10 00:00:00', freq='B')
>>> next_business_day('2000-1-10')
Timestamp('2000-01-11 00:00:00', freq='B')
>>> import pandas as pd
>>>
>>> def next_business_hour(x):
... lNextTwoBusinessHours = pd.date_range(x, periods=2, freq = 'BH')
... lHours = [h for h in lNextTwoBusinessHours if (h > pd.Timestamp(x))]
... print("next_business_hour" , (x , lHours[0]))
... return lHours[0]
...
>>> next_business_hour('2000-1-10 08:00:00')
next_business_hour ('2000-1-10 08:00:00', Timestamp('2000-01-10 09:00:00', freq='BH'))
Timestamp('2000-01-10 09:00:00', freq='BH')
>>> next_business_hour('2000-1-10 09:00:00')
next_business_hour ('2000-1-10 09:00:00', Timestamp('2000-01-10 10:00:00', freq='BH'))
Timestamp('2000-01-10 10:00:00', freq='BH')
>>> next_business_hour('2000-1-10 10:00:00')
next_business_hour ('2000-1-10 10:00:00', Timestamp('2000-01-10 11:00:00', freq='BH'))
Timestamp('2000-01-10 11:00:00', freq='BH')
>>> next_business_hour('2000-1-10 11:00:00')
next_business_hour ('2000-1-10 11:00:00', Timestamp('2000-01-10 12:00:00', freq='BH'))
Timestamp('2000-01-10 12:00:00', freq='BH')
>>> next_business_hour('2000-1-10 12:00:00')
next_business_hour ('2000-1-10 12:00:00', Timestamp('2000-01-10 13:00:00', freq='BH'))
Timestamp('2000-01-10 13:00:00', freq='BH')
>>> next_business_hour('2000-1-10 12:03:00')
next_business_hour ('2000-1-10 12:03:00', Timestamp('2000-01-10 13:03:00', freq='BH'))
Timestamp('2000-01-10 13:03:00', freq='BH')
>>> next_business_hour('2000-1-10 13:00:00')
next_business_hour ('2000-1-10 13:00:00', Timestamp('2000-01-10 14:00:00', freq='BH'))
Timestamp('2000-01-10 14:00:00', freq='BH')
>>> next_business_hour('2000-1-10 22:00:00')
next_business_hour ('2000-1-10 22:00:00', Timestamp('2000-01-11 09:00:00', freq='BH'))
Timestamp('2000-01-11 09:00:00', freq='BH')
>>> next_business_hour('2000-1-10 23:00:00')
next_business_hour ('2000-1-10 23:00:00', Timestamp('2000-01-11 09:00:00', freq='BH'))
Timestamp('2000-01-11 09:00:00', freq='BH')
>>> next_business_hour('2000-1-10 00:00:00')
next_business_hour ('2000-1-10 00:00:00', Timestamp('2000-01-10 09:00:00', freq='BH'))
Timestamp('2000-01-10 09:00:00', freq='BH')
>>>
Not sure if this feature will be implemented. User value ?
Delayed. Priority : low
Investigate business days / hours impact.
Impact : better handling of irregular physical time stamps (business dates). Incremental. May have a workaround with non-physical time equivalent.
Implementation impacts :
1000 consecutive business hours
pd.bdate_range('2000-1-1', periods=1000, freq = 'BH')