generated from openclimatefix/ocf-template
-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sukhil Patel
authored and
Sukhil Patel
committed
Aug 13, 2024
1 parent
feb7a8d
commit 6d08e10
Showing
1 changed file
with
5 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
"""Select time periods""" | ||
"""fill time periods""" | ||
|
||
import pandas as pd | ||
import numpy as np | ||
|
||
|
||
|
||
def fill_time_periods(time_periods: pd.DataFrame, freq: pd.Timedelta): | ||
datetimes = [] | ||
for _, row in time_periods.iterrows(): | ||
start_dt = pd.Timestamp(row["start_dt"]).ceil(freq) | ||
end_dt = pd.Timestamp(row["end_dt"]) | ||
datetimes.append(pd.date_range(start_dt, end_dt, freq=freq)) | ||
start_dts = time_periods["start_dt"].apply(lambda x: pd.Timestamp(x).ceil(freq)) | ||
end_dts = time_periods['end_dt'].apply(lambda x: pd.Timestamp(x)) | ||
date_ranges = [pd.date_range(start_dt, end_dt, freq=freq) for start_dt, end_dt in zip(start_dts, end_dts)] | ||
|
||
return pd.DatetimeIndex(np.concatenate(datetimes)) | ||
return pd.DatetimeIndex(np.concatenate(date_ranges)) |