Skip to content

Commit

Permalink
Merge branch 'maurerle-fix_between_time' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
p-snft committed Jul 31, 2024
2 parents 9c4ea83 + b6d1558 commit 4b6b268
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/demandlib/particular_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,29 @@ def simple_profile(self, annual_demand, **kwargs):

profile_factors = kwargs.get("profile_factors", default_factors)

self.dataframe["ind"] = 0

self.dataframe["ind"] = self.dataframe["ind"].mask(
cond=self.dataframe["weekday"].between_time(am, pm).isin(week),
other=profile_factors["week"]["day"],
)
self.dataframe["ind"] = self.dataframe["ind"].mask(
cond=self.dataframe["weekday"].between_time(pm, am).isin(week),
other=profile_factors["week"]["night"],
self.dataframe["ind"] = 0.0
day_mask = self.dataframe.index.indexer_between_time(am, pm)
night_mask = self.dataframe.index.indexer_between_time(pm, am)
day_filter = pd.Series(False, index=self.dataframe.index)
day_filter.iloc[day_mask] = True
night_filter = pd.Series(False, index=self.dataframe.index)
night_filter.iloc[night_mask] = True

week_filter = self.dataframe["weekday"].isin(week)
weekend_filter = self.dataframe["weekday"].isin(weekend)

# Update 'ind' column based on day/night filters and weekday/weekend conditions
self.dataframe.loc[day_filter & week_filter, "ind"] = profile_factors[
"week"
]["day"]
self.dataframe.loc[night_filter & week_filter, "ind"] = (
profile_factors["week"]["night"]
)
self.dataframe["ind"] = self.dataframe["ind"].mask(
cond=self.dataframe["weekday"].between_time(am, pm).isin(weekend),
other=profile_factors["weekend"]["day"],
self.dataframe.loc[day_filter & weekend_filter, "ind"] = (
profile_factors["weekend"]["day"]
)
self.dataframe["ind"] = self.dataframe["ind"].mask(
cond=self.dataframe["weekday"].between_time(pm, am).isin(weekend),
other=profile_factors["weekend"]["night"],
self.dataframe.loc[night_filter & weekend_filter, "ind"] = (
profile_factors["weekend"]["night"]
)

if self.dataframe["ind"].isnull().any(axis=0):
Expand Down

0 comments on commit 4b6b268

Please sign in to comment.