Fix valueerror in case of empty array files

This commit is contained in:
Matthias 2021-01-31 19:49:14 +01:00
parent 79087ba166
commit 2c80388b40
5 changed files with 22 additions and 5 deletions

View File

@ -86,8 +86,12 @@ class JsonDataHandler(IDataHandler):
filename = self._pair_data_filename(self._datadir, pair, timeframe)
if not filename.exists():
return DataFrame(columns=self._columns)
try:
pairdata = read_json(filename, orient='values')
pairdata.columns = self._columns
except ValueError:
logger.error(f"Could not load data for {pair}.")
return DataFrame(columns=self._columns)
pairdata = pairdata.astype(dtype={'open': 'float', 'high': 'float',
'low': 'float', 'close': 'float', 'volume': 'float'})
pairdata['date'] = to_datetime(pairdata['date'],

View File

@ -1181,7 +1181,7 @@ def test_start_list_data(testdatadir, capsys):
pargs['config'] = None
start_list_data(pargs)
captured = capsys.readouterr()
assert "Found 16 pair / timeframe combinations." in captured.out
assert "Found 17 pair / timeframe combinations." in captured.out
assert "\n| Pair | Timeframe |\n" in captured.out
assert "\n| UNITTEST/BTC | 1m, 5m, 8m, 30m |\n" in captured.out

View File

@ -646,7 +646,7 @@ def test_datahandler_ohlcv_get_available_data(testdatadir):
('ZEC/BTC', '5m'), ('UNITTEST/BTC', '1m'), ('ADA/BTC', '5m'),
('ETC/BTC', '5m'), ('NXT/BTC', '5m'), ('DASH/BTC', '5m'),
('XRP/ETH', '1m'), ('XRP/ETH', '5m'), ('UNITTEST/BTC', '30m'),
('UNITTEST/BTC', '8m')}
('UNITTEST/BTC', '8m'), ('NOPAIR/XXX', '4m')}
paircombs = JsonGzDataHandler.ohlcv_get_available_data(testdatadir)
assert set(paircombs) == {('UNITTEST/BTC', '8m')}
@ -672,6 +672,18 @@ def test_jsondatahandler_ohlcv_purge(mocker, testdatadir):
assert unlinkmock.call_count == 1
def test_jsondatahandler_ohlcv_load(testdatadir, caplog):
dh = JsonDataHandler(testdatadir)
df = dh.ohlcv_load('XRP/ETH', '5m')
assert len(df) == 711
# Failure case (empty array)
df1 = dh.ohlcv_load('NOPAIR/XXX', '4m')
assert len(df1) == 0
assert log_has("Could not load data for NOPAIR/XXX.", caplog)
assert df.columns.equals(df1.columns)
def test_jsondatahandler_trades_load(testdatadir, caplog):
dh = JsonGzDataHandler(testdatadir)
logmsg = "Old trades format detected - converting"

View File

@ -1109,7 +1109,7 @@ def test_list_available_pairs(botclient):
rc = client_get(client, f"{BASE_URI}/available_pairs")
assert_response(rc)
assert rc.json()['length'] == 12
assert rc.json()['length'] == 13
assert isinstance(rc.json()['pairs'], list)
rc = client_get(client, f"{BASE_URI}/available_pairs?timeframe=5m")

1
tests/testdata/NOPAIR_XXX-4m.json vendored Normal file
View File

@ -0,0 +1 @@
[]