BennyThadikaran / eod2

A fully automated script to download and update NSE EOD Historical stock, index and delivery data with added features
GNU General Public License v3.0
57 stars 18 forks source link

ValueError when using plot.py under certain conditions #124

Closed BennyThadikaran closed 5 months ago

BennyThadikaran commented 5 months ago
plot --watch hold-w --tf weekly --sma 30 --m-rs --preset-save hold
Preset saved as 'hold'
Traceback (most recent call last):
  File "/home/benny/Documents/python/eod2/src/plot.py", line 176, in <module>
    plotter.plot(symList[plotter.idx])
  File "/home/benny/Documents/python/eod2/src/defs/Plotter.py", line 218, in plot
    df = self._prepData(sym)
  File "/home/benny/Documents/python/eod2/src/defs/Plotter.py", line 742, in _prepData
    df = getDataFrame(
  File "/home/benny/Documents/python/eod2/src/defs/utils.py", line 176, in getDataFrame
    df = csv_loader(fpath, candle_count, end_date=toDate)
  File "/home/benny/Documents/python/eod2/src/defs/utils.py", line 128, in csv_loader
    current_dt = get_date(start, chunk)
  File "/home/benny/Documents/python/eod2/src/defs/utils.py", line 46, in get_date
    date = datetime.strptime(date_str, date_fmt)
  File "/usr/lib/python3.10/_strptime.py", line 568, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
  File "/usr/lib/python3.10/_strptime.py", line 349, in _strptime
    raise ValueError("time data %r does not match format %r" %
ValueError: time data 'Date' does not match format '%Y-%m-%d'

The error occurs when loading a file using the utils.py:csv_loader function, as a chunk is read from the start of the file.

Under some circumstances the final chunk may read something like this b'Date,Open,High,Low,Close,Volume,TOT'

Trying to parse the Date string as a Datetime value results in a ValueError. Issue was fixed by catching the ValueError, appending the chunk and returning the data as a DataFrame.

Updates to be posted soon.