MPCPy icon indicating copy to clipboard operation
MPCPy copied to clipboard

Optimization fails with pandas 0.24

Open dhblum opened this issue 5 years ago • 1 comments

This issue is to address an error that occurs in the function JModelica._get_control_results(), where the control results are converted to a pandas series with datetime index. The error occurs because of the lines:

timeindex = self._global_start_time_utc + timedelta;
ts_opt = pd.Series(data = data, index = timeindex).tz_localize('UTC');

In pandas 0.22, the first line creates a timezone unaware timeindex. In pandas 0.24, it creates a timezone aware timeindex, causing the second line to fail with

TypeError: Already tz-aware, use tz_convert to convert.

dhblum avatar Feb 26 '19 19:02 dhblum

There are additional errors in exodata.py when dealing with DST and reading epw files:

Traceback (most recent call last):
  File "/home/dhbubu/git/mpcpy/MPCPy/unittests/test_optimization.py", line 526, in setUp
    weather.collect_data(start_time_exodata, final_time_exodata);
  File "/home/dhbubu/git/mpcpy/MPCPy/mpcpy/exodata.py", line 279, in collect_data
    self._collect_data(start_time, final_time);
  File "/home/dhbubu/git/mpcpy/MPCPy/mpcpy/exodata.py", line 811, in _collect_data
    self._read_timeseries_from_epw();
  File "/home/dhbubu/git/mpcpy/MPCPy/mpcpy/exodata.py", line 881, in _read_timeseries_from_epw
    time_ambiguous = pd.to_datetime(time_ambiguous.args[0].split("'")[1])
  File "/home/dhbubu/.local/lib/python2.7/site-packages/pandas/core/tools/datetimes.py", line 611, in to_datetime
    result = convert_listlike(np.array([arg]), box, format)[0]
  File "/home/dhbubu/.local/lib/python2.7/site-packages/pandas/core/tools/datetimes.py", line 302, in _convert_listlike_datetimes
    allow_object=True)
  File "/home/dhbubu/.local/lib/python2.7/site-packages/pandas/core/arrays/datetimes.py", line 1866, in objects_to_datetime64ns
    raise e
ValueError: (u'Unknown string format:', 'ambiguous')

dhblum avatar Apr 25 '19 14:04 dhblum