make_weekend_sequence

make_weekend_sequence(start_date, end_date, friday_saturday=False, remove_holidays=False, country=None, engine='pandas')

Generate a sequence of weekend dates within a specified date range, optionally excluding holidays.

Parameters

Name Type Description Default
start_date str or datetime or pd.DatetimeIndex The start date of the date range. required
end_date str or datetime or pd.DatetimeIndex The end date of the date range. required
friday_saturday bool If True, generates a sequence with Friday and Saturday as weekends.If False (default), generates a sequence with Saturday and Sunday as weekends. False
remove_holidays (bool, optional) If True, excludes holidays (based on the specified country) from the generated sequence. If False (default), includes holidays in the sequence. False
country str The name of the country for which to generate holiday-specific sequences. Defaults to None, which uses the United States as the default country. None
engine str The engine parameter is used to specify the engine to use for generating a weekend series. It can be either “pandas” or “polars”. - The default value is “pandas”. - When “polars”, the function will internally use the polars library for generating a weekend series. This can be faster than using “pandas” for large datasets. 'pandas'

Returns

Type Description
pd.Series A Series containing the generated weekday dates.

Examples

import pandas as pd
import pytimetk as tk

# United States has Saturday and Sunday as weekends
tk.make_weekend_sequence("2023-01-01", "2023-01-31", 
                         friday_saturday = False, 
                         remove_holidays = True, 
                         country         = 'UnitedStates',
                         engine          = 'pandas')
0   2023-01-07
1   2023-01-08
2   2023-01-14
3   2023-01-15
4   2023-01-21
5   2023-01-22
6   2023-01-28
7   2023-01-29
Name: Weekend Dates, dtype: datetime64[ns]
# Saudi Arabia has Friday and Saturday as weekends
tk.make_weekend_sequence("2023-01-01", "2023-01-31", 
                         friday_saturday = True, 
                         remove_holidays = True, 
                         country         = 'SaudiArabia',
                         engine          = 'pandas')
0   2023-01-06
1   2023-01-07
2   2023-01-13
3   2023-01-14
4   2023-01-20
5   2023-01-21
6   2023-01-27
7   2023-01-28
Name: Weekend Dates, dtype: datetime64[ns]

# Saudi Arabia has Friday and Saturday as weekends, polars engine tk.make_weekend_sequence(“2023-01-01”, “2023-01-31”, friday_saturday = True, remove_holidays = True, country = ‘SaudiArabia’, engine = ’’) ```