8000 Merge branch '0.9.0_support' of github.com:influxdb/influxdb-python i… · timmartin19/influxdb-python@e3b3fe3 · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit e3b3fe3

Browse files
author
aviau
committed
Merge branch '0.9.0_support' of github.com:influxdb/influxdb-python into 0.9.0_support
2 parents d1b8edf + 28925ab commit e3b3fe3

File tree

7 files changed

+96
-22
lines changed

7 files changed

+96
-22
lines changed

README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ problems or submit contributions.
154154
.. _Issues: https://github.com/influxdb/influxdb-python/issues
155155

156156

157+
TODO
158+
====
159+
160+
The TODO/Roadmap can be found in Github bug tracker: https://github.com/influxdb/influxdb-python/issues/109
161+
162+
157163
Source code
158164
===========
159165

examples/tutorial_pandas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def main(host='localhost', port=8086):
2020
client.create_database(dbname)
2121

2222
print("Write DataFrame")
23-
client.write_points({'demo':df})
23+
client.write_points({'demo': df})
2424

2525
print("Read DataFrame")
2626
client.query("select * from demo")

examples/tutorial_serieshelper.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,49 @@
1+
"""
2+
Tutorial/Example how to use the class helper `SeriesHelper`
3+
"""
4+
15
from influxdb import InfluxDBClient
26
from influxdb import SeriesHelper
37

8+
# InfluxDB connections settings
9+
host = 'localhost'
10+
port = 8086
11+
user = 'root'
12+
password = 'root'
13+
dbname = 'mydb'
14+
15+
myclient = InfluxDBClient(host, port, user, password, dbname)
16+
17+
# Uncomment the following code if the database is not yet created
18+
# myclient.create_database(dbname)
19+
# myclient.create_retention_policy('awesome_policy', '3d', 3, default=True)
20+
421

522
class MySeriesHelper(SeriesHelper):
23+
# Meta class stores time series helper configuration.
624
class Meta:
7-
# Meta class stores time series helper configuration.
8-
client = InfluxDBClient()
925
# The client should be an instance of InfluxDBClient.
10-
series_name = 'events.stats.{server_name}'
26+
client = myclient
1127
# The series name must be a string. Add dependent fields/tags in curly brackets.
12-
fields = ['some_stat']
28+
series_name = 'events.stats.{server_name}'
1329
# Defines all the fields in this time series.
14-
tags = ['server_name']
30+
fields = ['some_stat', 'other_stat']
1531
# Defines all the tags for the series.
16-
bulk_size = 5
32+
tags = ['server_name']
1733
# Defines the number of data points to store prior to writing on the wire.
34+
bulk_size = 5
35+
# autocommit must be set to True when using bulk_size
36+
autocommit = True
37+
1838

1939
# The following will create *five* (immutable) data points.
2040
# Since bulk_size is set to 5, upon the fifth construction call, *all* data
2141
# points will be written on the wire via MySeriesHelper.Meta.client.
22-
MySeriesHelper(server_name='us.east-1', some_stat=159)
23-
MySeriesHelper(server_name='us.east-1', some_stat=158)
24-
MySeriesHelper(server_name='us.east-1', some_stat=157)
25-
MySeriesHelper(server_name='us.east-1', some_stat=156)
26-
MySeriesHelper(server_name='us.east-1', some_stat=155)
42+
MySeriesHelper(server_name='us.east-1', some_stat=159, other_stat=10)
43+
MySeriesHelper(server_name='us.east-1', some_stat=158, other_stat=20)
44+
MySeriesHelper(server_name='us.east-1', some_stat=157, other_stat=30)
45+
MySeriesHelper(server_name='us.east-1', some_stat=156, other_stat=40)
46+
MySeriesHelper(server_name='us.east-1', some_stat=155, other_stat=50)
2747

2848
# To manually submit data points which are not yet written, call commit:
2949
MySeriesHelper.commit()

influxdb/dataframe_client.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
from .client import InfluxDBClient
99

10+
try:
11+
import pandas as pd
12+
except ImportError:
13+
pd = None
14+
1015

1116
class DataFrameClient(InfluxDBClient):
1217
"""
@@ -17,13 +22,9 @@ class DataFrameClient(InfluxDBClient):
1722

1823
def __init__(self, *args, **kwargs):
1924
super(DataFrameClient, self).__init__(*args, **kwargs)
20-
try:
21-
global pd
22-
import pandas as pd
23-
except ImportError as ex:
25+
if not pd:
2426
raise ImportError(
25-
'DataFrameClient requires Pandas, "{ex}" problem importing'
26-
.format(ex=str(ex))
27+
'DataFrameClient requires Pandas'
2728
)
2829

2930
self.EPOCH = pd.Timestamp('1970-01-01 00:00:00.000+00:00')

test-requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
nose
2+
nose-cov
23
mock
3-
requests-mock
4+
requests-mock

tests/influxdb/chunked_json_test.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import unittest
4+
5+
from influxdb import chunked_json
6+
7+
8+
class TestChunkJson(unittest.TestCase):
9+
10+
@classmethod
11+
def setUpClass(cls):
12+
super(TestChunkJson, cls).setUpClass()
13+
14+
def test_load(self):
15+
"""
16+
Tests reading a sequence of JSON values from a string
17+
"""
18+
example_response = \
19+
'{"results": [{"series": [{"name": "sdfsdfsdf", ' \
20+
'"columns": ["time", "value"], "values": ' \
21+
'[["2009-11-10T23:00:00Z", 0.64]]}]}, {"series": ' \
22+
'[{"name": "cpu_load_short", "columns": ["time", "value"], ' \
23+
'"values": [["2009-11-10T23:00:00Z", 0.64]]}]}]}'
24+
25+
res = list(chunked_json.loads(example_response))
26+
# import ipdb; ipdb.set_trace()
27+
28+
# self.assertTrue(res)
29+
self.assertListEqual(
30+
[
31+
{
32+
'results': [
33+
{'series': [{
34+
'values': [['2009-11-10T23:00:00Z', 0.64]],
35+
'name': 'sdfsdfsdf',
36+
'columns':
37+
['time', 'value']}]},
38+
{'series': [{
39+
'values': [['2009-11-10T23:00:00Z', 0.64]],
40+
'name': 'cpu_load_short',
41+
'columns': ['time', 'value']}]}
42+
]
43+
}
44+
],
45+
res
46+
)

tests/influxdb/client_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def setUp(self):
7474
"region": "us-west"
7575
},
7676
"timestamp": "2009-11-10T23:00:00Z",
77-
"values": {
77+
"fields": {
7878
"value": 0.64
7979
}
8080
}
@@ -114,7 +114,7 @@ def test_write(self):
114114
"tags": {"host": "server01",
115115
"region": "us-west"},
116116
"timestamp": "2009-11-10T23:00:00Z",
117-
"values": {"value": 0.64}}]}
117+
"fields": {"value": 0.64}}]}
118118
)
119119

120120
self.assertEqual(
@@ -125,7 +125,7 @@ def test_write(self):
125125
"tags": {"host": "server01",
126126
"region": "us-west"},
127127
"timestamp": "2009-11-10T23:00:00Z",
128-
"values": {"value": 0.64}}]}
128+
"fields": {"value": 0.64}}]}
129129
)
130130

131131
def test_write_points(self):

0 commit comments

Comments
 (0)
0