-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved business day support #20884
Comments
I'm not a fan of the global config whatsoever. We need to find a different solution. The cleanest is probably by not (only) using bd = BusinessDays(week_mask = [True, True, True, True, False, False, True])
df = df.with_columns(pl.col('price').rolling_mean_by('date', bd(3)).over('asset')) Then any temporal function that accepts business days we change window_size: timedelta | str to window_size: timedelta | str | BusinessDays |
From discussion:
|
Example where you would like to mix time and business days:
|
thanks @alexander-beedie ! in this case, would you have a table with the the market opening hour varies depending on the day? in which case, would a |
If normalised, would more likely be an inner join against such a table (as you'd expect the answer to be exact), but it might also be something supplied from an API running outside of Polars, hence wanting to mix & match at the expression level (eg: "next business day according to [externally supplied calendar] at [externally supplied offset]"). Definitely workarounds available of course ;) |
This comes up repeatedly when I teach Polars.
add_business_days
/business_day_count
are a start, but people really want to be able to use business days ingroup_by_dynamic
/rolling
. Concrete requests people have brought up are:Expr.is_business_day
rolling_mean_by
, such as "rolling mean over the last 3 business days"group_by_dynamic
Implementation-wise, I don't think this would be terrible -
add_business_day
could be added alongsidepolars/crates/polars-time/src/windows/duration.rs
Lines 487 to 531 in c2accef
'bd'
could be accepted into the Polars string language.The main difficulty I see is, API-wise, how to specify custom weekday masks and holiday calendars. In Expr.dt.add_business_days, this is solved by having
week_mask
andholidays
arguments. However, addingweek_mask
andholidays
arguments to every temporal function which handles intervals (rolling_*_by
,offset_by
,group_by_dynamic
,rolling
,upsample
, ...) seems infeasible - I don't think it's warranted to expand all these functions' APIs for functionality which sure is useful but only perhaps to 1% of users.Would it work to instead have
week_mask
andholidays
be configurable withpl.Config
? So people could do something likeThe text was updated successfully, but these errors were encountered: