Skip to content

Commit

Permalink
Black
Browse files Browse the repository at this point in the history
  • Loading branch information
birgits committed Aug 2, 2024
1 parent 5fb7d15 commit 8894298
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 71 deletions.
20 changes: 13 additions & 7 deletions src/demandlib/particular_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,24 @@ def simple_profile(self, annual_demand, **kwargs):

# Update 'ind' column based on day/night filters and
# weekday/weekend/holiday conditions
self.dataframe.loc[day_filter & week_filter, "ind"] = \
profile_factors["week"]["day"]
self.dataframe.loc[night_filter & week_filter, "ind"] = \
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.loc[day_filter & weekend_filter, "ind"] = \
)
self.dataframe.loc[day_filter & weekend_filter, "ind"] = (
profile_factors["weekend"]["day"]
self.dataframe.loc[night_filter & weekend_filter, "ind"] = \
)
self.dataframe.loc[night_filter & weekend_filter, "ind"] = (
profile_factors["weekend"]["night"]
self.dataframe.loc[day_filter & holiday_filter, "ind"] = \
)
self.dataframe.loc[day_filter & holiday_filter, "ind"] = (
profile_factors["holiday"]["day"]
self.dataframe.loc[night_filter & holiday_filter, "ind"] = \
)
self.dataframe.loc[night_filter & holiday_filter, "ind"] = (
profile_factors["holiday"]["night"]
)

# Check for NAN values in the dataframe
if self.dataframe["ind"].isnull().any(axis=0):
Expand Down
205 changes: 141 additions & 64 deletions tests/test_particular_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ class TestIndustrialLoadProfile:
@classmethod
def setup_class(cls):
dt_index = pd.date_range(
datetime.datetime(2010, 1, 1, 0),
periods=24 * 7,
freq="1H"
datetime.datetime(2010, 1, 1, 0), periods=24 * 7, freq="1H"
)
holidays = {
datetime.date(2010, 1, 1): "New year",
Expand All @@ -35,26 +33,44 @@ def test_simple_profile(self):

# check factors in self.dataframe["ind"]
# holiday
assert self.ilp.dataframe.at[
pd.Timestamp("2010-01-01 6:00"), "ind"] == 0.7
assert self.ilp.dataframe.at[
pd.Timestamp("2010-01-01 7:00"), "ind"] == 0.9
assert self.ilp.dataframe.at[
pd.Timestamp("2010-01-01 23:00"), "ind"] == 0.9
assert (
self.ilp.dataframe.at[pd.Timestamp("2010-01-01 6:00"), "ind"]
== 0.7
)
assert (
self.ilp.dataframe.at[pd.Timestamp("2010-01-01 7:00"), "ind"]
== 0.9
)
assert (
self.ilp.dataframe.at[pd.Timestamp("2010-01-01 23:00"), "ind"]
== 0.9
)
# weekend day
assert self.ilp.dataframe.at[
pd.Timestamp("2010-01-02 6:00"), "ind"] == 0.7
assert self.ilp.dataframe.at[
pd.Timestamp("2010-01-02 7:00"), "ind"] == 0.9
assert self.ilp.dataframe.at[
pd.Timestamp("2010-01-02 23:00"), "ind"] == 0.9
assert (
self.ilp.dataframe.at[pd.Timestamp("2010-01-02 6:00"), "ind"]
== 0.7
)
assert (
self.ilp.dataframe.at[pd.Timestamp("2010-01-02 7:00"), "ind"]
== 0.9
)
assert (
self.ilp.dataframe.at[pd.Timestamp("2010-01-02 23:00"), "ind"]
== 0.9
)
# week day
assert self.ilp.dataframe.at[
pd.Timestamp("2010-01-04 6:00"), "ind"] == 0.6
assert self.ilp.dataframe.at[
pd.Timestamp("2010-01-04 7:00"), "ind"] == 0.8
assert self.ilp.dataframe.at[
pd.Timestamp("2010-01-04 23:00"), "ind"] == 0.8
assert (
self.ilp.dataframe.at[pd.Timestamp("2010-01-04 6:00"), "ind"]
== 0.6
)
assert (
self.ilp.dataframe.at[pd.Timestamp("2010-01-04 7:00"), "ind"]
== 0.8
)
assert (
self.ilp.dataframe.at[pd.Timestamp("2010-01-04 23:00"), "ind"]
== 0.8
)

# check sum of factors to make sure not only the tested factors are
# correct
Expand All @@ -72,41 +88,66 @@ def test_simple_profile(self):
weekend = [1, 6, 7]
df = self.ilp.simple_profile(
1.0,
week=week, weekend=weekend,
week=week,
weekend=weekend,
profile_factors=profile_factors,
am=datetime.time(6, 30, 0),
pm=datetime.time(22, 00, 0),
)

# check factors in self.dataframe["ind"]
# holiday
assert self.ilp.dataframe.at[
pd.Timestamp("2010-01-01 6:00"), "ind"] == 0.3
assert self.ilp.dataframe.at[
pd.Timestamp("2010-01-01 7:00"), "ind"] == 0.8
assert self.ilp.dataframe.at[
pd.Timestamp("2010-01-01 23:00"), "ind"] == 0.3
assert (
self.ilp.dataframe.at[pd.Timestamp("2010-01-01 6:00"), "ind"]
== 0.3
)
assert (
self.ilp.dataframe.at[pd.Timestamp("2010-01-01 7:00"), "ind"]
== 0.8
)
assert (
self.ilp.dataframe.at[pd.Timestamp("2010-01-01 23:00"), "ind"]
== 0.3
)
# weekend day
assert self.ilp.dataframe.at[
pd.Timestamp("2010-01-02 6:00"), "ind"] == 0.4
assert self.ilp.dataframe.at[
pd.Timestamp("2010-01-02 7:00"), "ind"] == 0.7
assert self.ilp.dataframe.at[
pd.Timestamp("2010-01-02 22:00"), "ind"] == 0.7
assert (
self.ilp.dataframe.at[pd.Timestamp("2010-01-02 6:00"), "ind"]
== 0.4
)
assert (
self.ilp.dataframe.at[pd.Timestamp("2010-01-02 7:00"), "ind"]
== 0.7
)
assert (
self.ilp.dataframe.at[pd.Timestamp("2010-01-02 22:00"), "ind"]
== 0.7
)
# Monday - now set to be weekend day
assert self.ilp.dataframe.at[
pd.Timestamp("2010-01-04 6:00"), "ind"] == 0.4
assert self.ilp.dataframe.at[
pd.Timestamp("2010-01-04 7:00"), "ind"] == 0.7
assert self.ilp.dataframe.at[
pd.Timestamp("2010-01-04 23:00"), "ind"] == 0.4
assert (
self.ilp.dataframe.at[pd.Timestamp("2010-01-04 6:00"), "ind"]
== 0.4
)
assert (
self.ilp.dataframe.at[pd.Timestamp("2010-01-04 7:00"), "ind"]
== 0.7
)
assert (
self.ilp.dataframe.at[pd.Timestamp("2010-01-04 23:00"), "ind"]
== 0.4
)
# week day
assert self.ilp.dataframe.at[
pd.Timestamp("2010-01-05 6:00"), "ind"] == 0.5
assert self.ilp.dataframe.at[
pd.Timestamp("2010-01-05 7:00"), "ind"] == 0.6
assert self.ilp.dataframe.at[
pd.Timestamp("2010-01-05 23:00"), "ind"] == 0.5
assert (
self.ilp.dataframe.at[pd.Timestamp("2010-01-05 6:00"), "ind"]
== 0.5
)
assert (
self.ilp.dataframe.at[pd.Timestamp("2010-01-05 7:00"), "ind"]
== 0.6
)
assert (
self.ilp.dataframe.at[pd.Timestamp("2010-01-05 23:00"), "ind"]
== 0.5
)

# check sum of factors to make sure not only the tested factors are
# correct
Expand Down Expand Up @@ -147,26 +188,62 @@ def test_simple_profile(self):

# check factors in self.dataframe["ind"]
# holiday - now treated as Sunday
assert self.ilp_holiday.dataframe.at[
pd.Timestamp("2010-01-01 6:00"), "ind"] == 0.4
assert self.ilp_holiday.dataframe.at[
pd.Timestamp("2010-01-01 7:00"), "ind"] == 0.7
assert self.ilp_holiday.dataframe.at[
pd.Timestamp("2010-01-01 23:00"), "ind"] == 0.7
assert (
self.ilp_holiday.dataframe.at[
pd.Timestamp("2010-01-01 6:00"), "ind"
]
== 0.4
)
assert (
self.ilp_holiday.dataframe.at[
pd.Timestamp("2010-01-01 7:00"), "ind"
]
== 0.7
)
assert (
self.ilp_holiday.dataframe.at[
pd.Timestamp("2010-01-01 23:00"), "ind"
]
== 0.7
)
# weekend day
assert self.ilp_holiday.dataframe.at[
pd.Timestamp("2010-01-02 6:00"), "ind"] == 0.4
assert self.ilp_holiday.dataframe.at[
pd.Timestamp("2010-01-02 7:00"), "ind"] == 0.7
assert self.ilp_holiday.dataframe.at[
pd.Timestamp("2010-01-02 23:00"), "ind"] == 0.7
assert (
self.ilp_holiday.dataframe.at[
pd.Timestamp("2010-01-02 6:00"), "ind"
]
== 0.4
)
assert (
self.ilp_holiday.dataframe.at[
pd.Timestamp("2010-01-02 7:00"), "ind"
]
== 0.7
)
assert (
self.ilp_holiday.dataframe.at[
pd.Timestamp("2010-01-02 23:00"), "ind"
]
== 0.7
)
# week day
assert self.ilp_holiday.dataframe.at[
pd.Timestamp("2010-01-04 6:00"), "ind"] == 0.5
assert self.ilp_holiday.dataframe.at[
pd.Timestamp("2010-01-04 7:00"), "ind"] == 0.6
assert self.ilp_holiday.dataframe.at[
pd.Timestamp("2010-01-04 23:00"), "ind"] == 0.6
assert (
self.ilp_holiday.dataframe.at[
pd.Timestamp("2010-01-04 6:00"), "ind"
]
== 0.5
)
assert (
self.ilp_holiday.dataframe.at[
pd.Timestamp("2010-01-04 7:00"), "ind"
]
== 0.6
)
assert (
self.ilp_holiday.dataframe.at[
pd.Timestamp("2010-01-04 23:00"), "ind"
]
== 0.6
)

# check sum of factors to make sure not only the tested factors are
# correct
Expand Down

0 comments on commit 8894298

Please sign in to comment.