Skip to content

Commit 7bc1dcd

Browse files
authored
Remove pandas.datetime (#60)
The pandas.datetime class is now deprecated. Import from datetime instead (GH30610). pandas-dev/pandas#30610
1 parent a83cd2b commit 7bc1dcd

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

dispaset/postprocessing/data_handler.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ def get_sim_results(path='.', cache=None, temp_path=None, return_xarray=False, r
123123
# Set datetime index:
124124
StartDate = inputs['config']['StartDate']
125125
StopDate = inputs['config']['StopDate'] # last day of the simulation with look-ahead period
126-
StopDate_long = pd.datetime(*StopDate) + dt.timedelta(days=inputs['config']['LookAhead'])
127-
index = pd.date_range(start=pd.datetime(*StartDate), end=pd.datetime(*StopDate), freq='h')
128-
index_long = pd.date_range(start=pd.datetime(*StartDate), end=StopDate_long, freq='h')
126+
StopDate_long = dt.datetime(*StopDate) + dt.timedelta(days=inputs['config']['LookAhead'])
127+
index = pd.date_range(start=dt.datetime(*StartDate), end=dt.datetime(*StopDate), freq='h')
128+
index_long = pd.date_range(start=dt.datetime(*StartDate), end=StopDate_long, freq='h')
129129

130130
keys = ['LostLoad_2U', 'LostLoad_3U', 'LostLoad_MaxPower', 'LostLoad_MinPower', 'LostLoad_RampUp',
131131
'LostLoad_RampDown', 'LostLoad_2D','ShadowPrice', 'StorageShadowPrice'] #'status'
@@ -280,8 +280,8 @@ def ds_to_df(inputs):
280280
# config = parameters['Config']['val']
281281
try:
282282
config = inputs['config']
283-
first_day = pd.datetime(config['StartDate'][0], config['StartDate'][1], config['StartDate'][2], 0)
284-
last_day = pd.datetime(config['StopDate'][0], config['StopDate'][1], config['StopDate'][2], 23)
283+
first_day = dt.datetime(config['StartDate'][0], config['StartDate'][1], config['StartDate'][2], 0)
284+
last_day = dt.datetime(config['StopDate'][0], config['StopDate'][1], config['StopDate'][2], 23)
285285
dates = pd.date_range(start=first_day, end=last_day, freq='1h')
286286
timeindex = True
287287
except KeyError:
@@ -344,4 +344,4 @@ def ds_to_df(inputs):
344344
else:
345345
logging.error('Only three dimensions currently supported. Parameter ' + p + ' has ' + str(dim) + ' dimensions.')
346346
sys.exit(1)
347-
return out
347+
return out

dispaset/postprocessing/postprocessing.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from __future__ import division
99

10+
import datetime as dt
1011
import logging
1112
import sys
1213

@@ -205,7 +206,7 @@ def get_result_analysis(inputs, results):
205206

206207
StartDate = inputs['config']['StartDate']
207208
StopDate = inputs['config']['StopDate']
208-
index = pd.date_range(start=pd.datetime(*StartDate), end=pd.datetime(*StopDate), freq='h')
209+
index = pd.date_range(start=dt.datetime(*StartDate), end=dt.datetime(*StopDate), freq='h')
209210

210211
# Aggregated values:
211212
demand = {}

dispaset/preprocessing/data_handler.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import datetime as dt
12
import logging
23
import os
34
import sys
@@ -327,8 +328,8 @@ def load_time_series(config,path,header='infer'):
327328
elif len(data) == 8760:
328329
logging.info('A numerical index has been found for file ' + path +
329330
'. Since it contains 8760 elements, it is assumed that it corresponds to a whole year')
330-
data.index = pd.DatetimeIndex(start=pd.datetime(*(config['idx'][0].year,1,1,0,0)),
331-
end=pd.datetime(*(config['idx'][0].year,12,31,23,59,59)),
331+
data.index = pd.DatetimeIndex(start=dt.datetime(*(config['idx'][0].year,1,1,0,0)),
332+
end=dt.datetime(*(config['idx'][0].year,12,31,23,59,59)),
332333
freq=commons['TimeStep'])
333334
else:
334335
logging.critical('A numerical index has been found for file ' + path +

dispaset/preprocessing/preprocessing.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ def build_simulation(config, profiles=None):
6565
config['StopDate'] = (y_end, m_end, d_end, 23, 59, 00) # updating stopdate to the end of the day
6666

6767
# Indexes of the simulation:
68-
config['idx'] = pd.DatetimeIndex(pd.date_range(start=pd.datetime(*config['StartDate']),
69-
end=pd.datetime(*config['StopDate']),
68+
config['idx'] = pd.DatetimeIndex(pd.date_range(start=dt.datetime(*config['StartDate']),
69+
end=dt.datetime(*config['StopDate']),
7070
freq=commons['TimeStep'])).tz_localize(None)
7171

7272

7373
# Indexes for the whole year considered in StartDate
74-
idx_year = pd.DatetimeIndex(pd.date_range(start=pd.datetime(*(config['StartDate'][0],1,1,0,0)),
75-
end=pd.datetime(*(config['StartDate'][0],12,31,23,59,59)),
74+
idx_year = pd.DatetimeIndex(pd.date_range(start=dt.datetime(*(config['StartDate'][0],1,1,0,0)),
75+
end=dt.datetime(*(config['StartDate'][0],12,31,23,59,59)),
7676
freq=commons['TimeStep'])
7777
)
7878

@@ -943,8 +943,8 @@ def mid_term_scheduling(config, zones, profiles=None):
943943
config['StopDate'] = (y_end, m_end, d_end, 23, 59, 00) # updating stopdate to the end of the day
944944

945945
# Indexes of the simualtion:
946-
idx_std = pd.DatetimeIndex(start=pd.datetime(*config['StartDate']),
947-
end=pd.datetime(*config['StopDate']),
946+
idx_std = pd.DatetimeIndex(start=dt.datetime(*config['StartDate']),
947+
end=dt.datetime(*config['StopDate']),
948948
freq=commons['TimeStep'])
949949
idx_utc_noloc = idx_std - dt.timedelta(hours=1)
950950
idx = idx_utc_noloc

dispaset/pyomo/model.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#######################################################################################################################
1515

1616

17+
import datetime as dt
1718
import sys
1819
import os
1920
import logging
@@ -691,8 +692,8 @@ def DispaSolve(sets, parameters, LPFormulation=False, path_cplex = ''):
691692
Nhours = len(sets['h'])
692693

693694
# Build pandas indexes based on the config variables:
694-
first = pd.datetime(config['FirstDay', 'year'], config['FirstDay', 'month'], config['FirstDay', 'day'], 0, 0, 0)
695-
last = pd.datetime(config['LastDay', 'year'], config['LastDay', 'month'], config['LastDay', 'day'], 23, 59, 59)
695+
first = dt.datetime(config['FirstDay', 'year'], config['FirstDay', 'month'], config['FirstDay', 'day'], 0, 0, 0)
696+
last = dt.datetime(config['LastDay', 'year'], config['LastDay', 'month'], config['LastDay', 'day'], 23, 59, 59)
696697

697698
# Index corresponding to the data:
698699
index_all = pd.DatetimeIndex(start=first, end=last, freq='h')

0 commit comments

Comments
 (0)