Skip to content

Commit f8a72cd

Browse files
committed
Added handling of empty result sets
1 parent 8a806ae commit f8a72cd

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

influxdb/misc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ def query(self, query, time_precision='s', chunked=False):
7171
result = InfluxDBClient.query(self, query=query,
7272
time_precision=time_precision,
7373
chunked=chunked)
74-
return self._to_dataframe(result[0], time_precision)
74+
if len(result) > 0:
75+
return self._to_dataframe(result[0], time_precision)
76+
else:
77+
return result
7578

7679
def _to_dataframe(self, json_result, time_precision):
7780
try:

tests/influxdb/misc_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ def test_query_into_dataframe(self):
159159
result = cli.query('select column_one from foo;')
160160
assert_frame_equal(dataframe, result)
161161

162+
def test_query_with_empty_result(self):
163+
with _mocked_session('get', 200, []):
164+
cli = DataFrameClient('host', 8086, 'username', 'password', 'db')
165+
result = cli.query('select column_one from foo;')
166+
assert result == []
167+
162168
def test_list_series(self):
163169
response = [
164170
{

0 commit comments

Comments
 (0)