Skip to content

Commit 373e787

Browse files
committed
Fix deprecations in pandas 3
1 parent f28d9e4 commit 373e787

3 files changed

Lines changed: 19 additions & 13 deletions

File tree

lpagg/BDEW.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import numpy as np
3939
import pandas as pd
4040
from pandas.tseries.frequencies import to_offset
41+
from pandas.api.types import is_numeric_dtype
4142
import logging
4243
import importlib.resources
4344

@@ -91,9 +92,18 @@ def load_BDEW_style_profiles(source_file, weather_data, cfg, houses_dict,
9192
skiprows=[0], header=[0, 1], index_col=[0],
9293
skipfooter=1,
9394
)
94-
weather_daily = (weather_data.resample('D', label='right', closed='right')
95-
.mean(numeric_only=True))
96-
# print(weather_daily)
95+
96+
agg_dict = dict()
97+
for col in weather_data.columns:
98+
if is_numeric_dtype(weather_data[col]):
99+
agg_dict[col] = 'mean'
100+
else:
101+
agg_dict[col] = 'first'
102+
103+
weather_daily = (weather_data
104+
.shift(periods=-1, freq="infer")
105+
.resample('D', label='left', closed='left')
106+
.agg(agg_dict))
97107

98108
houses_list = settings['houses_list_BDEW']
99109
multiindex = pd.MultiIndex.from_product([houses_list, [energy_type]],
@@ -127,12 +137,8 @@ def load_BDEW_style_profiles(source_file, weather_data, cfg, houses_dict,
127137
profile_year = pd.Series(dtype='float')
128138
profiles_daily = []
129139
for date in weather_daily.index:
130-
weekday = weather_data.loc[date]['weekday_BDEW']
131-
season = weather_data.loc[date]['season_BDEW']
132-
# Important: In order identify the weekday of the resampled days,
133-
# we labled them 'right'. From now on we need the label 'left',
134-
# so we substract '1 day' from each date:
135-
date -= pd.Timedelta('1 day')
140+
weekday = weather_daily.loc[date]['weekday_BDEW']
141+
season = weather_daily.loc[date]['season_BDEW']
136142

137143
source_profile = source_df[house_type][season, weekday]
138144

lpagg/agg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,8 +1281,8 @@ def apply_DST(df, tz_default='Etc/GMT-1', tz_DST='CET', normalize=True):
12811281
df_DST = df_DST[df_DST.index.notnull()]
12821282
# In October, the repeated DST-hour is not in the index yet.
12831283
# Reindex with the initial index. This will cause missing rows in October.
1284-
# We fill them with method forward fill.
1285-
df_DST = df_DST.reindex_like(df_default, method='ffill')
1284+
# We fill them with the 'forward fill' method.
1285+
df_DST = df_DST.reindex_like(df_default).ffill()
12861286
# Finally, make the DataFrame timezone-unaware before returning it.
12871287
df_DST = df_DST.tz_localize(None)
12881288

lpagg/simultaneity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def copy_df_columns(df, copies_list, level=None):
246246
else:
247247
df_tmp = pd.concat([df[col]], keys=[copy_name],
248248
names=[level], axis=1)
249-
df_new = pd.concat([df_new, df_tmp], axis='columns')
249+
df_new = pd.concat([df_new, df_tmp], axis='columns', sort=False)
250250
return df_new
251251

252252

@@ -705,7 +705,7 @@ def plot_shifted_lineplots(df_shift, df_ref, cfg):
705705

706706
# Save raw data
707707
df_excel = pd.concat([load_shift, load_ref], axis='columns',
708-
keys=[txt_shift, txt_ref])
708+
keys=[txt_shift, txt_ref], sort=False)
709709
df_excel.to_excel(os.path.join(cfg['print_folder'],
710710
ylabel + ' (shift)'+'.xlsx'))
711711

0 commit comments

Comments
 (0)