Skip to content

Commit

Permalink
Remove pandas.datetime (#60)
Browse files Browse the repository at this point in the history
The pandas.datetime class is now deprecated.
Import from datetime instead (GH30610).

pandas-dev/pandas#30610
  • Loading branch information
corralien committed Feb 5, 2020
1 parent a83cd2b commit 7bc1dcd
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
12 changes: 6 additions & 6 deletions dispaset/postprocessing/data_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ def get_sim_results(path='.', cache=None, temp_path=None, return_xarray=False, r
# Set datetime index:
StartDate = inputs['config']['StartDate']
StopDate = inputs['config']['StopDate'] # last day of the simulation with look-ahead period
StopDate_long = pd.datetime(*StopDate) + dt.timedelta(days=inputs['config']['LookAhead'])
index = pd.date_range(start=pd.datetime(*StartDate), end=pd.datetime(*StopDate), freq='h')
index_long = pd.date_range(start=pd.datetime(*StartDate), end=StopDate_long, freq='h')
StopDate_long = dt.datetime(*StopDate) + dt.timedelta(days=inputs['config']['LookAhead'])
index = pd.date_range(start=dt.datetime(*StartDate), end=dt.datetime(*StopDate), freq='h')
index_long = pd.date_range(start=dt.datetime(*StartDate), end=StopDate_long, freq='h')

keys = ['LostLoad_2U', 'LostLoad_3U', 'LostLoad_MaxPower', 'LostLoad_MinPower', 'LostLoad_RampUp',
'LostLoad_RampDown', 'LostLoad_2D','ShadowPrice', 'StorageShadowPrice'] #'status'
Expand Down Expand Up @@ -280,8 +280,8 @@ def ds_to_df(inputs):
# config = parameters['Config']['val']
try:
config = inputs['config']
first_day = pd.datetime(config['StartDate'][0], config['StartDate'][1], config['StartDate'][2], 0)
last_day = pd.datetime(config['StopDate'][0], config['StopDate'][1], config['StopDate'][2], 23)
first_day = dt.datetime(config['StartDate'][0], config['StartDate'][1], config['StartDate'][2], 0)
last_day = dt.datetime(config['StopDate'][0], config['StopDate'][1], config['StopDate'][2], 23)
dates = pd.date_range(start=first_day, end=last_day, freq='1h')
timeindex = True
except KeyError:
Expand Down Expand Up @@ -344,4 +344,4 @@ def ds_to_df(inputs):
else:
logging.error('Only three dimensions currently supported. Parameter ' + p + ' has ' + str(dim) + ' dimensions.')
sys.exit(1)
return out
return out
3 changes: 2 additions & 1 deletion dispaset/postprocessing/postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from __future__ import division

import datetime as dt
import logging
import sys

Expand Down Expand Up @@ -205,7 +206,7 @@ def get_result_analysis(inputs, results):

StartDate = inputs['config']['StartDate']
StopDate = inputs['config']['StopDate']
index = pd.date_range(start=pd.datetime(*StartDate), end=pd.datetime(*StopDate), freq='h')
index = pd.date_range(start=dt.datetime(*StartDate), end=dt.datetime(*StopDate), freq='h')

# Aggregated values:
demand = {}
Expand Down
5 changes: 3 additions & 2 deletions dispaset/preprocessing/data_handler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime as dt
import logging
import os
import sys
Expand Down Expand Up @@ -327,8 +328,8 @@ def load_time_series(config,path,header='infer'):
elif len(data) == 8760:
logging.info('A numerical index has been found for file ' + path +
'. Since it contains 8760 elements, it is assumed that it corresponds to a whole year')
data.index = pd.DatetimeIndex(start=pd.datetime(*(config['idx'][0].year,1,1,0,0)),
end=pd.datetime(*(config['idx'][0].year,12,31,23,59,59)),
data.index = pd.DatetimeIndex(start=dt.datetime(*(config['idx'][0].year,1,1,0,0)),
end=dt.datetime(*(config['idx'][0].year,12,31,23,59,59)),
freq=commons['TimeStep'])
else:
logging.critical('A numerical index has been found for file ' + path +
Expand Down
12 changes: 6 additions & 6 deletions dispaset/preprocessing/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ def build_simulation(config, profiles=None):
config['StopDate'] = (y_end, m_end, d_end, 23, 59, 00) # updating stopdate to the end of the day

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


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

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

# Indexes of the simualtion:
idx_std = pd.DatetimeIndex(start=pd.datetime(*config['StartDate']),
end=pd.datetime(*config['StopDate']),
idx_std = pd.DatetimeIndex(start=dt.datetime(*config['StartDate']),
end=dt.datetime(*config['StopDate']),
freq=commons['TimeStep'])
idx_utc_noloc = idx_std - dt.timedelta(hours=1)
idx = idx_utc_noloc
Expand Down
5 changes: 3 additions & 2 deletions dispaset/pyomo/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#######################################################################################################################


import datetime as dt
import sys
import os
import logging
Expand Down Expand Up @@ -691,8 +692,8 @@ def DispaSolve(sets, parameters, LPFormulation=False, path_cplex = ''):
Nhours = len(sets['h'])

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

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

0 comments on commit 7bc1dcd

Please sign in to comment.