Skip to content

Commit

Permalink
Improve compatibility with Pandas 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
p-snft committed Jun 27, 2024
1 parent 157847a commit 2500bf7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
2 changes: 1 addition & 1 deletion examples/electricity_demand_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
print("Or resample the DataFrame to hourly values using the mean() " "method.")

# Resample 15-minute values to hourly values.
elec_demand_resampled = elec_demand.resample("H").mean()
elec_demand_resampled = elec_demand.resample("h").mean()
print(elec_demand_resampled.sum())

# Plot demand
Expand Down
2 changes: 1 addition & 1 deletion examples/heat_demand_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
# Create DataFrame for 2010
demand = pd.DataFrame(
index=pd.date_range(
datetime.datetime(2010, 1, 1, 0), periods=8760, freq="H"
datetime.datetime(2010, 1, 1, 0), periods=8760, freq="h"
)
)

Expand Down
4 changes: 2 additions & 2 deletions src/demandlib/bdew/heat_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ def weighted_temperature(self, how="geometric_series"):
.resample("D")
.mean()
.reindex(self.df.index)
.fillna(method="ffill")
.fillna(method="bfill")
.ffill()
.bfill()
)

if how == "geometric_series":
Expand Down
12 changes: 4 additions & 8 deletions src/demandlib/particular_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,21 @@ def simple_profile(self, annual_demand, **kwargs):

self.dataframe["ind"] = 0

self.dataframe["ind"].mask(
self.dataframe["ind"] = self.dataframe["ind"].mask(
cond=self.dataframe["weekday"].between_time(am, pm).isin(week),
other=profile_factors["week"]["day"],
inplace=True,
)
self.dataframe["ind"].mask(
self.dataframe["ind"] = self.dataframe["ind"].mask(
cond=self.dataframe["weekday"].between_time(pm, am).isin(week),
other=profile_factors["week"]["night"],
inplace=True,
)
self.dataframe["ind"].mask(
self.dataframe["ind"] = self.dataframe["ind"].mask(
cond=self.dataframe["weekday"].between_time(am, pm).isin(weekend),
other=profile_factors["weekend"]["day"],
inplace=True,
)
self.dataframe["ind"].mask(
self.dataframe["ind"] = self.dataframe["ind"].mask(
cond=self.dataframe["weekday"].between_time(pm, am).isin(weekend),
other=profile_factors["weekend"]["night"],
inplace=True,
)

if self.dataframe["ind"].isnull().any(axis=0):
Expand Down
13 changes: 6 additions & 7 deletions src/demandlib/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ def add_weekdays2df(time_df, holidays=None, holiday_is_sunday=False):
if holidays is not None:
if isinstance(holidays, dict):
holidays = list(holidays.keys())
time_df["weekday"].mask(
cond=pd.to_datetime(time_df["date"]).isin(
pd.to_datetime(holidays)
),
other=0,
inplace=True,
)
time_df["weekday"] = time_df["weekday"].mask(
cond=pd.to_datetime(time_df["date"]).isin(
pd.to_datetime(holidays)
),
other=0,
)

if holiday_is_sunday:
time_df.weekday = time_df.weekday.mask(
Expand Down

0 comments on commit 2500bf7

Please sign in to comment.