From 2500bf74f0c9f47afc9e62424fd869292745c221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Sch=C3=B6nfeldt?= Date: Thu, 27 Jun 2024 13:27:03 +0200 Subject: [PATCH] Improve compatibility with Pandas 3.0 --- examples/electricity_demand_example.py | 2 +- examples/heat_demand_example.py | 2 +- src/demandlib/bdew/heat_building.py | 4 ++-- src/demandlib/particular_profiles.py | 12 ++++-------- src/demandlib/tools.py | 13 ++++++------- 5 files changed, 14 insertions(+), 19 deletions(-) diff --git a/examples/electricity_demand_example.py b/examples/electricity_demand_example.py index a2555a1..38a2874 100644 --- a/examples/electricity_demand_example.py +++ b/examples/electricity_demand_example.py @@ -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 diff --git a/examples/heat_demand_example.py b/examples/heat_demand_example.py index 768105c..ed76263 100644 --- a/examples/heat_demand_example.py +++ b/examples/heat_demand_example.py @@ -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" ) ) diff --git a/src/demandlib/bdew/heat_building.py b/src/demandlib/bdew/heat_building.py index f565021..0c47430 100644 --- a/src/demandlib/bdew/heat_building.py +++ b/src/demandlib/bdew/heat_building.py @@ -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": diff --git a/src/demandlib/particular_profiles.py b/src/demandlib/particular_profiles.py index bb64158..2fb0039 100644 --- a/src/demandlib/particular_profiles.py +++ b/src/demandlib/particular_profiles.py @@ -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): diff --git a/src/demandlib/tools.py b/src/demandlib/tools.py index 0521ac8..e2b565a 100644 --- a/src/demandlib/tools.py +++ b/src/demandlib/tools.py @@ -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(