Skip to content

Commit

Permalink
Refactor function
Browse files Browse the repository at this point in the history
  • 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.
13 changes: 5 additions & 8 deletions ocf_data_sampler/select/fill_time_periods.py
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))

0 comments on commit 6d08e10

Please sign in to comment.