is_public_holiday¶
is_public_holiday(date, country_code)
Description¶
Return true if date
corresponds to a public holiday in country_code
- Always return
false
if date is not between year 1974 and year 2076. country_code
must be among[AO, AR, AW, AU, AT, AZ, BD, BY, BE, BO, BW, BR, BG, BI, CA, CL, CN, CO, HR, CU, CW, CY, CZ, DK, DJ, DO, EG, EE, ET, FI, FR, GE, DE, GR, HN, HK, HU, IS, IN, IE, IL, IT, JM, JP, KZ, KE, KR, LV, LS, LT, LU, MG, MW, MY, MT, MX, MD, MA, MZ, NA, NL, NZ, NI, NG, MK, NO, PY, PE, PL, PT, RO, RU, SA, RS, SG, SK, SI, ZA, ES, SZ, SE, CH, TW, TN, TR, UA, AE, GB, US, UY, UZ, VE, VN, ZM, ZW]
- Holiday dates come from
python-holidays
.
Usage¶
Call or Deploy is_public_holiday
?
Call is_public_holiday
directly
The easiest way to use bigfunctions
is_public_holiday
function is deployed in 39 public datasets for all of the 39 BigQuery regions.- It can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
- (You need to use the dataset in the same region as your datasets otherwise you may have a function not found error)
Public BigFunctions Datasets
Region | Dataset |
---|---|
eu |
bigfunctions.eu |
us |
bigfunctions.us |
europe-west1 |
bigfunctions.europe_west1 |
asia-east1 |
bigfunctions.asia_east1 |
... | ... |
Deploy is_public_holiday
in your project
Why deploy?
- You may prefer to deploy
is_public_holiday
in your own project to build and manage your own catalog of functions. - This is particularly useful if you want to create private functions (for example calling your internal APIs).
- Get started by reading the framework page
Deployment
is_public_holiday
function can be deployed with:
pip install bigfunctions
bigfun get is_public_holiday
bigfun deploy is_public_holiday
Examples¶
select bigfunctions.eu.is_public_holiday(date('2022-07-14'), "FR")
select bigfunctions.us.is_public_holiday(date('2022-07-14'), "FR")
select bigfunctions.europe_west1.is_public_holiday(date('2022-07-14'), "FR")
+-------------------+
| is_public_holiday |
+-------------------+
| true |
+-------------------+
Use cases¶
A common use case for the is_public_holiday
function is adjusting business metrics or forecasts based on public holiday occurrences.
Scenario: An e-commerce company wants to analyze daily sales data and understand the impact of public holidays on sales performance.
Implementation using is_public_holiday
:
SELECT
order_date,
total_sales,
bigfunctions.YOUR_REGION.is_public_holiday(order_date, 'US') AS is_public_holiday_us -- Replace YOUR_REGION with your BigQuery region
FROM
`your_project.your_dataset.sales_data`
WHERE order_date BETWEEN '2023-01-01' AND '2023-12-31';
Explanation:
- The query retrieves
order_date
andtotal_sales
from thesales_data
table. - It then uses the
is_public_holiday
function to determine whether eachorder_date
falls on a public holiday in the US. The region for bigfunctions should be replaced with your BigQuery region (e.g.bigfunctions.us
,bigfunctions.eu
). - The result includes a new column
is_public_holiday_us
indicating whether each date is a public holiday (true/false).
Further analysis:
Having this information, the company can:
- Compare sales: Compare sales figures on public holidays versus regular days to quantify the impact. They might see lower sales on some holidays (e.g., Christmas, when stores might be closed) and higher sales on others (e.g., Black Friday).
- Adjust forecasts: Use the historical holiday data to improve sales forecasting accuracy by accounting for the expected impact of upcoming public holidays. For example, they might anticipate increased online sales in the week leading up to a holiday.
- Identify trends: Identify any specific product categories or customer segments that are particularly affected by public holidays.
- Optimize marketing campaigns: Plan and execute targeted marketing campaigns around public holidays, taking into account predicted sales fluctuations.
This is just one example. The is_public_holiday
function can be useful in various other scenarios involving date analysis, such as:
- Supply chain management: Predicting potential delays due to public holidays in different countries.
- Human resources: Calculating employee working hours, considering public holidays.
- Financial analysis: Understanding market behavior around public holidays.
By integrating the is_public_holiday
function into BigQuery queries, businesses can gain valuable insights and make more informed decisions based on a better understanding of the influence of public holidays on their operations.
Need help or Found a bug?
Get help using is_public_holiday
The community can help! Engage the conversation on Slack
We also provide professional suppport.
Report a bug about is_public_holiday
If the function does not work as expected, please
- report a bug so that it can be improved.
- or open the discussion with the community on Slack.
We also provide professional suppport.