Skip to content

Limit the maximum pre-period end date to upgrade date#88

Open
samuelwnaylor wants to merge 4 commits intomainfrom
pre-date-max-limit
Open

Limit the maximum pre-period end date to upgrade date#88
samuelwnaylor wants to merge 4 commits intomainfrom
pre-date-max-limit

Conversation

@samuelwnaylor
Copy link
Copy Markdown
Collaborator

If the analysis_last_dt_utc_start is >1 year post upgrade date then ensure that if the years_offset_for_pre_period is specified as 1 year, then the maximum end date of the pre-period is the upgrade date (with 1 day as contingency).

If the `analysis_last_dt_utc_start` is >1 year post upgrade date then
ensure that if the `years_offset_for_pre_period` is specified as 1 year,
then the maximum end date of the pre-period is the upgrade date (with 1
day as contingency).
@samuelwnaylor samuelwnaylor marked this pull request as ready for review March 26, 2026 16:57
@samuelwnaylor samuelwnaylor requested a review from aclerc as a code owner March 26, 2026 16:57
Copy link
Copy Markdown
Contributor

@aclerc aclerc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Sam, this is nice validation! A few comments, happy to discuss

Comment on lines +452 to +455
if pre_last_dt_utc_start > cfg_dct["upgrade_first_dt_utc_start"]:
pre_last_dt_utc_start = pd.to_datetime(cfg_dct["upgrade_first_dt_utc_start"]) - pd.Timedelta(
days=1
) # One day for contingency
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd take out the one day for contingency. That way this simplifies to pre_last_dt_utc_start being clipped to an upper value of cfg_dct["upgrade_first_dt_utc_start"]. Otherwise pre_last_dt_utc_start is allowed to be as late as cfg_dct["upgrade_first_dt_utc_start"], but then as soon as it goes over it gets shoved back a day which seems inconsistent

another thought is that we want pre and post to not contain the same timestamps, so really we want to clip pre_last_dt_utc_start to be no later than upgrade_first_dt_utc_start minus the analysis timebase. If you change that here then I think the inconsistency with validation is fixed (other comment).

"""Check that the pre-period does not extend over the upgrade date.

Check that if the `analysis_last_dt_utc_start` is >1 year post upgrade that if the `years_offset_for_pre_period` is
1 year, then the maximum end date of the pre-period is the upgrade date (with a days contingency).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as per other comments I'd set the pre period to the upgrade timestamp minus the analysis timebase

@samuelwnaylor samuelwnaylor requested a review from aclerc March 27, 2026 14:06
Copy link
Copy Markdown
Contributor

@aclerc aclerc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good! just some minor requests

Comment on lines +454 to +457
if pre_last_dt_utc_start > cfg_dct["upgrade_first_dt_utc_start"]:
pre_last_dt_utc_start = pd.to_datetime(cfg_dct["upgrade_first_dt_utc_start"]) - pd.Timedelta(
seconds=cfg_dct.get("timebase_s", DEFAULT_TIMEBASE_S)
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here you should test for greater than the value you are clipping it to, pd.to_datetime(cfg_dct["upgrade_first_dt_utc_start"]) - pd.Timedelta(seconds=cfg_dct.get("timebase_s", DEFAULT_TIMEBASE_S). What a great walrus opportunity

@samuelwnaylor samuelwnaylor requested a review from aclerc March 27, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants