Skip to content

Commit 596f617

Browse files
authored
fix: code style of source files (#80)
1 parent 91e8b47 commit 596f617

30 files changed

+393
-462
lines changed

.circleci/config.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ jobs:
6868
command: |
6969
pip install flake8 --user
7070
flake8 influxdb_client_3/
71+
- run:
72+
name: Checks style consistency across tests.
73+
command: |
74+
pip install flake8 --user
75+
flake8 tests/
76+
- run:
77+
name: Checks style consistency across examples.
78+
command: |
79+
pip install flake8 --user
80+
flake8 Examples/
7181
check-twine:
7282
docker:
7383
- image: *default-python
@@ -102,7 +112,7 @@ workflows:
102112
not:
103113
equal: [ scheduled_pipeline, << pipeline.trigger_source >> ]
104114
jobs:
105-
# - check-code-style
115+
- check-code-style
106116
# - check-docstyle
107117
- check-twine
108118
- tests-python:

.flake8

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[flake8]
2+
count = True
3+
max-line-length = 120
4+
5+
# W504: Line break occurred after a binary operator
6+
ignore = W504

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22

33
### Bugfix
44

5-
1. [#77](https://github.com/InfluxCommunity/influxdb3-python/pull/77): Support using pandas nullable types
5+
1. [#77](https://github.com/InfluxCommunity/influxdb3-python/pull/77): Support using pandas nullable types
6+
7+
### Others
8+
9+
- [#80](https://github.com/InfluxCommunity/influxdb3-python/pull/80): Integrate code style check into CI

Examples/batching_example.py

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1+
import datetime
12
import random
2-
import pymongo
3-
import pandas as pd
3+
44
from bson import ObjectId
5+
56
import influxdb_client_3 as InfluxDBClient3
6-
import pandas as pd
7-
import numpy as np
87
from influxdb_client_3 import write_client_options, WritePrecision, WriteOptions, InfluxDBError
9-
import datetime
10-
import time
118

129

1310
class BatchingCallback(object):
@@ -42,26 +39,24 @@ def retry(self, conf, data: str, exception: InfluxDBError):
4239
callback = BatchingCallback()
4340

4441
write_options = WriteOptions(batch_size=5_000,
45-
flush_interval=10_000,
46-
jitter_interval=2_000,
47-
retry_interval=5_000,
48-
max_retries=5,
49-
max_retry_delay=30_000,
50-
exponential_base=2)
42+
flush_interval=10_000,
43+
jitter_interval=2_000,
44+
retry_interval=5_000,
45+
max_retries=5,
46+
max_retry_delay=30_000,
47+
exponential_base=2)
5148

5249
wco = write_client_options(success_callback=callback.success,
53-
error_callback=callback.error,
54-
retry_callback=callback.retry,
55-
WriteOptions=write_options
56-
)
50+
error_callback=callback.error,
51+
retry_callback=callback.retry,
52+
WriteOptions=write_options
53+
)
5754
# Opening InfluxDB client with a batch size of 5k points or flush interval
5855
# of 10k ms and gzip compression
5956
with InfluxDBClient3.InfluxDBClient3(token=token,
6057
host=url,
6158
org=org,
6259
database=database, enable_gzip=True, write_client_options=wco) as _client:
63-
64-
6560
# Creating iterator for one hour worth of data (6 sensor readings per
6661
# minute)
6762
for i in range(0, 525600):
@@ -93,25 +88,25 @@ def retry(self, conf, data: str, exception: InfluxDBError):
9388
bcWh).field(
9489
"bdW",
9590
bdW).field(
96-
"bdWh",
97-
bdWh).field(
98-
"cPvWh",
99-
cPvWh).field(
100-
"cW",
101-
cW).field(
102-
"cWh",
103-
cWh).field(
104-
"eWh",
105-
eWh).field(
106-
"iWh",
107-
iWh).field(
108-
"pW",
109-
pW).field(
110-
"pWh",
111-
pWh).field(
112-
"scWh",
113-
scWh).time(
114-
now.strftime('%Y-%m-%dT%H:%M:%SZ'),
91+
"bdWh",
92+
bdWh).field(
93+
"cPvWh",
94+
cPvWh).field(
95+
"cW",
96+
cW).field(
97+
"cWh",
98+
cWh).field(
99+
"eWh",
100+
eWh).field(
101+
"iWh",
102+
iWh).field(
103+
"pW",
104+
pW).field(
105+
"pWh",
106+
pWh).field(
107+
"scWh",
108+
scWh).time(
109+
now.strftime('%Y-%m-%dT%H:%M:%SZ'),
115110
WritePrecision.S)
116111

117112
# Writing point (InfluxDB automatically batches writes into sets of

Examples/cloud_dedicated_query.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import influxdb_client_3 as InfluxDBClient3
2-
import pandas as pd
3-
import numpy as np
42

53
client = InfluxDBClient3.InfluxDBClient3(
64
token="",
75
host="b0c7cce5-8dbc-428e-98c6-7f996fb96467.a.influxdb.io",
86
org="6a841c0c08328fb1",
97
database="flight2")
108

11-
129
table = client.query(
1310
query="SELECT * FROM flight WHERE time > now() - 4h",
1411
language="influxql")

Examples/community/custom_url.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
from influxdb_client_3 import InfluxDBClient3,InfluxDBError,WriteOptions,write_client_options
2-
import pandas as pd
31
import random
42

3+
import pandas as pd
4+
5+
from influxdb_client_3 import InfluxDBClient3, InfluxDBError, WriteOptions, write_client_options
6+
57

68
class BatchingCallback(object):
79

@@ -14,36 +16,38 @@ def error(self, conf, data: str, exception: InfluxDBError):
1416
def retry(self, conf, data: str, exception: InfluxDBError):
1517
print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}")
1618

17-
callback = BatchingCallback()
1819

20+
callback = BatchingCallback()
1921

2022
write_options = WriteOptions(batch_size=100,
21-
flush_interval=10_000,
22-
jitter_interval=2_000,
23-
retry_interval=5_000,
24-
max_retries=5,
25-
max_retry_delay=30_000,
26-
exponential_base=2)
23+
flush_interval=10_000,
24+
jitter_interval=2_000,
25+
retry_interval=5_000,
26+
max_retries=5,
27+
max_retry_delay=30_000,
28+
exponential_base=2)
2729

2830
wco = write_client_options(success_callback=callback.success,
29-
error_callback=callback.error,
30-
retry_callback=callback.retry,
31-
WriteOptions=write_options
32-
)
31+
error_callback=callback.error,
32+
retry_callback=callback.retry,
33+
WriteOptions=write_options
34+
)
3335

3436
client = InfluxDBClient3(
3537
token="",
3638
host="https://eu-central-1-1.aws.cloud2.influxdata.com:442",
3739
org="6a841c0c08328fb1",
38-
database="pokemon-codex", enable_gzip=True, write_client_options=wco, write_port_overwrite=443, query_port_overwrite=443)
40+
database="pokemon-codex", enable_gzip=True, write_client_options=wco, write_port_overwrite=443,
41+
query_port_overwrite=443)
3942

40-
now = pd.Timestamp.now(tz='UTC').floor('ms')
43+
now = pd.Timestamp.now(tz='UTC').floor('ms')
4144

4245
# Lists of possible trainers
4346
trainers = ["ash", "brock", "misty", "gary", "jessie", "james"]
4447

4548
# Read the CSV into a DataFrame
46-
pokemon_df = pd.read_csv("https://gist.githubusercontent.com/ritchie46/cac6b337ea52281aa23c049250a4ff03/raw/89a957ff3919d90e6ef2d34235e6bf22304f3366/pokemon.csv")
49+
pokemon_df = pd.read_csv(
50+
"https://gist.githubusercontent.com/ritchie46/cac6b337ea52281aa23c049250a4ff03/raw/89a957ff3919d90e6ef2d34235e6bf22304f3366/pokemon.csv") # noqa: E501
4751

4852
# Creating an empty list to store the data
4953
data = []
@@ -57,17 +61,17 @@ def retry(self, conf, data: str, exception: InfluxDBError):
5761
# Generating random data
5862
for i in range(num_entries):
5963
trainer = random.choice(trainers)
60-
64+
6165
# Randomly select a row from pokemon_df
6266
random_pokemon = pokemon_df.sample().iloc[0]
6367
caught = random_pokemon['Name']
64-
68+
6569
# Count the number of times this trainer has caught this Pokémon
6670
if (trainer, caught) in trainer_pokemon_counts:
6771
trainer_pokemon_counts[(trainer, caught)] += 1
6872
else:
6973
trainer_pokemon_counts[(trainer, caught)] = 1
70-
74+
7175
# Get the number for this combination of trainer and Pokémon
7276
num = trainer_pokemon_counts[(trainer, caught)]
7377

@@ -93,9 +97,8 @@ def retry(self, conf, data: str, exception: InfluxDBError):
9397
# Print the DataFrame
9498
print(caught_pokemon_df)
9599

96-
97100
try:
98101
client.write(caught_pokemon_df, data_frame_measurement_name='caught',
99-
data_frame_tag_columns=['trainer', 'id', 'num'])
102+
data_frame_tag_columns=['trainer', 'id', 'num'])
100103
except Exception as e:
101-
print(f"Error writing point: {e}")
104+
print(f"Error writing point: {e}")
Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
import random
2-
import pymongo
3-
import pandas as pd
4-
from bson import ObjectId
5-
import influxdb_client_3 as InfluxDBClient3
6-
import pandas as pd
7-
import numpy as np
8-
from influxdb_client_3 import write_client_options, WritePrecision, WriteOptions, InfluxDBError
9-
import datetime
101
import time
112

3+
import influxdb_client_3 as InfluxDBClient3
4+
from influxdb_client_3 import write_client_options, WriteOptions, InfluxDBError
5+
126

137
class BatchingCallback(object):
148

@@ -22,44 +16,41 @@ def retry(self, conf, data: str, exception: InfluxDBError):
2216
print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}")
2317

2418

25-
26-
2719
# InfluxDB connection details
2820
token = ""
2921
org = "6a841c0c08328fb1"
3022
dbfrom = "a"
3123
dbto = "b"
3224
url = "eu-central-1-1.aws.cloud2.influxdata.com"
3325
measurement = "airSensors"
34-
taglist= []
26+
taglist = []
3527

3628
callback = BatchingCallback()
3729

3830
write_options = WriteOptions(batch_size=5_000,
39-
flush_interval=10_000,
40-
jitter_interval=2_000,
41-
retry_interval=5_000,
42-
max_retries=5,
43-
max_retry_delay=30_000,
44-
exponential_base=2)
31+
flush_interval=10_000,
32+
jitter_interval=2_000,
33+
retry_interval=5_000,
34+
max_retries=5,
35+
max_retry_delay=30_000,
36+
exponential_base=2)
4537

4638
wco = write_client_options(success_callback=callback.success,
47-
error_callback=callback.error,
48-
retry_callback=callback.retry,
49-
WriteOptions=write_options
50-
)
39+
error_callback=callback.error,
40+
retry_callback=callback.retry,
41+
WriteOptions=write_options
42+
)
5143
# Opening InfluxDB client with a batch size of 5k points or flush interval
5244
# of 10k ms and gzip compression
5345
with InfluxDBClient3.InfluxDBClient3(token=token,
5446
host=url,
5547
org=org,
56-
enable_gzip=True, write_client_options=wco) as _client:
48+
enable_gzip=True, write_client_options=wco) as _client:
5749
query = f"SHOW TAG KEYS FROM {measurement}"
5850
tags = _client.query(query=query, language="influxql", database=dbfrom)
5951
tags = tags.to_pydict()
6052
taglist = tags['tagKey']
6153

62-
6354
query = f"SELECT * FROM {measurement}"
6455
reader = _client.query(query=query, language="influxql", database=dbfrom, mode="chunk")
6556
try:
@@ -69,10 +60,8 @@ def retry(self, conf, data: str, exception: InfluxDBError):
6960
pd = batch.to_pandas()
7061
pd = pd.set_index('time')
7162
print(pd)
72-
_client.write(database=dbto, record=pd, data_frame_measurement_name=measurement, data_frame_tag_columns=taglist)
63+
_client.write(database=dbto, record=pd, data_frame_measurement_name=measurement,
64+
data_frame_tag_columns=taglist)
7365
time.sleep(2)
7466
except StopIteration:
7567
print("No more chunks to read")
76-
77-
78-

0 commit comments

Comments
 (0)