Skip to content

Commit 62a0ba1

Browse files
authored
feat: DeleteApi uses default value from InfluxDBClient.org if org parameter is not specified (#412)
1 parent 892c774 commit 62a0ba1

File tree

9 files changed

+59
-33
lines changed

9 files changed

+59
-33
lines changed

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
## 1.27.0 [unreleased]
22

3+
### Features
4+
1. [#412](https://github.com/influxdata/influxdb-client-python/pull/412): `DeleteApi` uses default value from `InfluxDBClient.org` if an `org` parameter is not specified
5+
36
### CI
4-
1. [#411](https://github.com/influxdata/influxdb-client-python/pull/411): Use new Codecov uploader for reporting code coverage
7+
1. [#411](https://github.com/influxdata/influxdb-client-python/pull/411): Use new Codecov uploader for reporting code coverage
58

69
## 1.26.0 [2022-02-18]
710

docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def setup(app):
3131

3232

3333
project = 'influxdb_client'
34-
copyright = '2019 InfluxData, Inc'
34+
copyright = '2022 InfluxData, Inc'
3535
author = 'Robert Hajek, Jakub Bednar'
3636

3737
autoclass_content = 'both'

influxdb_client/client/bucket_api.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def create_bucket(self, bucket=None, bucket_name=None, org_id=None, retention_ru
2929
:param bucket_name: bucket name
3030
:param retention_rules: retention rules array or single BucketRetentionRules
3131
:param str, Organization org: specifies the organization for create the bucket;
32-
take the ID, Name or Organization;
33-
if it's not specified then is used default from client.org.
32+
Take the ``ID``, ``Name`` or ``Organization``.
33+
If not specified the default value from ``InfluxDBClient.org`` is used.
3434
:return: Bucket
3535
If the method is called asynchronously,
3636
returns the request thread.

influxdb_client/client/delete_api.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
"""Delete time series data from InfluxDB."""
22

33
from datetime import datetime
4+
from typing import Union
45

5-
from influxdb_client import DeleteService, DeletePredicateRequest
6+
from influxdb_client import DeleteService, DeletePredicateRequest, Organization
67
from influxdb_client.client.util.date_utils import get_date_helper
8+
from influxdb_client.client.util.helpers import get_org_query_param
79

810

911
class DeleteApi(object):
@@ -14,15 +16,18 @@ def __init__(self, influxdb_client):
1416
self._influxdb_client = influxdb_client
1517
self._service = DeleteService(influxdb_client.api_client)
1618

17-
def delete(self, start: datetime, stop: object, predicate: object, bucket: str, org: str) -> None:
19+
def delete(self, start: Union[str, datetime], stop: Union[str, datetime], predicate: str, bucket: str,
20+
org: Union[str, Organization, None] = None) -> None:
1821
"""
1922
Delete Time series data from InfluxDB.
2023
21-
:param start: start time
22-
:param stop: stop time
23-
:param predicate: predicate
24-
:param bucket: bucket id or name from which data will be deleted
25-
:param org: organization id or name
24+
:param str, datetime.datetime start: start time
25+
:param str, datetime.datetime stop: stop time
26+
:param str predicate: predicate
27+
:param str bucket: bucket id or name from which data will be deleted
28+
:param str, Organization org: specifies the organization to delete data from.
29+
Take the ``ID``, ``Name`` or ``Organization``.
30+
If not specified the default value from ``InfluxDBClient.org`` is used.
2631
:return:
2732
"""
2833
date_helper = get_date_helper()
@@ -31,5 +36,7 @@ def delete(self, start: datetime, stop: object, predicate: object, bucket: str,
3136
if isinstance(stop, datetime):
3237
stop = date_helper.to_utc(stop)
3338

39+
org_param = get_org_query_param(org=org, client=self._influxdb_client, required_id=False)
40+
3441
predicate_request = DeletePredicateRequest(start=start, stop=stop, predicate=predicate)
35-
return self._service.post_delete(delete_predicate_request=predicate_request, bucket=bucket, org=org)
42+
return self._service.post_delete(delete_predicate_request=predicate_request, bucket=bucket, org=org_param)

influxdb_client/client/influxdb_client.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ def __init__(self, url, token, debug=None, timeout=10_000, enable_gzip=False, or
3737
:param timeout: HTTP client timeout setting for a request specified in milliseconds.
3838
If one number provided, it will be total request timeout.
3939
It can also be a pair (tuple) of (connection, read) timeouts.
40-
:param enable_gzip: Enable Gzip compression for http requests. Currently only the "Write" and "Query" endpoints
40+
:param enable_gzip: Enable Gzip compression for http requests. Currently, only the "Write" and "Query" endpoints
4141
supports the Gzip compression.
42-
:param org: organization name (used as a default in query and write API)
42+
:param org: organization name (used as a default in Query, Write and Delete API)
4343
:key bool verify_ssl: Set this to false to skip verifying SSL certificate when calling API from https server.
4444
:key str ssl_ca_cert: Set this to customize the certificate file to verify the peer.
4545
:key str proxy: Set this to configure the http proxy to be used (ex. http://localhost:3128)

influxdb_client/client/query_api.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ def query_csv(self, query: str, org=None, dialect: Dialect = default_dialect, pa
5555
5656
:param query: a Flux query
5757
:param str, Organization org: specifies the organization for executing the query;
58-
take the ID, Name or Organization;
59-
if it's not specified then is used default from client.org.
58+
Take the ``ID``, ``Name`` or ``Organization``.
59+
If not specified the default value from ``InfluxDBClient.org`` is used.
6060
:param dialect: csv dialect format
6161
:param params: bind parameters
6262
:return: The returned object is an iterator. Each iteration returns a row of the CSV file
@@ -74,8 +74,8 @@ def query_raw(self, query: str, org=None, dialect=default_dialect, params: dict
7474
7575
:param query: a Flux query
7676
:param str, Organization org: specifies the organization for executing the query;
77-
take the ID, Name or Organization;
78-
if it's not specified then is used default from client.org.
77+
Take the ``ID``, ``Name`` or ``Organization``.
78+
If not specified the default value from ``InfluxDBClient.org`` is used.
7979
:param dialect: csv dialect format
8080
:param params: bind parameters
8181
:return: str
@@ -92,8 +92,8 @@ def query(self, query: str, org=None, params: dict = None) -> List['FluxTable']:
9292
9393
:param query: the Flux query
9494
:param str, Organization org: specifies the organization for executing the query;
95-
take the ID, Name or Organization;
96-
if it's not specified then is used default from client.org.
95+
Take the ``ID``, ``Name`` or ``Organization``.
96+
If not specified the default value from ``InfluxDBClient.org`` is used.
9797
:param params: bind parameters
9898
:return:
9999
"""
@@ -115,8 +115,8 @@ def query_stream(self, query: str, org=None, params: dict = None) -> Generator['
115115
116116
:param query: the Flux query
117117
:param str, Organization org: specifies the organization for executing the query;
118-
take the ID, Name or Organization;
119-
if it's not specified then is used default from client.org.
118+
Take the ``ID``, ``Name`` or ``Organization``.
119+
If not specified the default value from ``InfluxDBClient.org`` is used.
120120
:param params: bind parameters
121121
:return:
122122
"""
@@ -138,8 +138,8 @@ def query_data_frame(self, query: str, org=None, data_frame_index: List[str] = N
138138
139139
:param query: the Flux query
140140
:param str, Organization org: specifies the organization for executing the query;
141-
take the ID, Name or Organization;
142-
if it's not specified then is used default from client.org.
141+
Take the ``ID``, ``Name`` or ``Organization``.
142+
If not specified the default value from ``InfluxDBClient.org`` is used.
143143
:param data_frame_index: the list of columns that are used as DataFrame index
144144
:param params: bind parameters
145145
:return:
@@ -165,8 +165,8 @@ def query_data_frame_stream(self, query: str, org=None, data_frame_index: List[s
165165
166166
:param query: the Flux query
167167
:param str, Organization org: specifies the organization for executing the query;
168-
take the ID, Name or Organization;
169-
if it's not specified then is used default from client.org.
168+
Take the ``ID``, ``Name`` or ``Organization``.
169+
If not specified the default value from ``InfluxDBClient.org`` is used.
170170
:param data_frame_index: the list of columns that are used as DataFrame index
171171
:param params: bind parameters
172172
:return:

influxdb_client/client/write_api.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ def write(self, bucket: str, org: str = None,
292292
293293
:param str bucket: specifies the destination bucket for writes (required)
294294
:param str, Organization org: specifies the destination organization for writes;
295-
take the ID, Name or Organization;
296-
if it's not specified then is used default from client.org.
295+
take the ID, Name or Organization.
296+
If not specified the default value from ``InfluxDBClient.org`` is used.
297297
:param WritePrecision write_precision: specifies the precision for the unix timestamps within
298298
the body line-protocol. The precision specified on a Point has precedes
299299
and is use for write.

tests/test_DeleteApi.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,20 @@ def test_delete_buckets_by_name(self):
6060

6161
start = "1970-01-01T00:00:00.000000001Z"
6262
stop = "1970-01-01T00:00:00.000000012Z"
63-
self._delete_and_verify(start, stop)
63+
self._delete_and_verify(start, stop, self.organization.name)
64+
65+
def test_delete_org_parameters_types(self):
66+
67+
orgs = [
68+
self.organization,
69+
self.organization.id,
70+
self.organization.name,
71+
None
72+
]
73+
74+
for org in orgs:
75+
self._write_data()
76+
self._delete_and_verify("1970-01-01T00:00:00.000000001Z", "1970-01-01T00:00:00.000000012Z", org)
6477

6578
def test_start_stop_types(self):
6679
starts_stops = [
@@ -70,10 +83,10 @@ def test_start_stop_types(self):
7083
]
7184
for start_stop in starts_stops:
7285
self._write_data()
73-
self._delete_and_verify(start_stop[0], start_stop[1])
86+
self._delete_and_verify(start_stop[0], start_stop[1], self.organization.name)
7487

75-
def _delete_and_verify(self, start, stop):
76-
self.delete_api.delete(start, stop, "", bucket=self.bucket.name, org=self.organization.name)
88+
def _delete_and_verify(self, start, stop, org):
89+
self.delete_api.delete(start, stop, "", bucket=self.bucket.name, org=org)
7790
flux_tables = self.client.query_api().query(
7891
f'from(bucket:"{self.bucket.name}") |> range(start: 1970-01-01T00:00:00.000000001Z)',
7992
org=self.organization.id)

tests/test_WriteApiDataFrame.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,10 @@ def test_write_num_py_floats(self):
327327
from influxdb_client.extras import pd, np
328328
now = pd.Timestamp('2020-04-05 00:00+00:00')
329329

330-
for np_float_type in [np.float, np.float16, np.float32, np.float64, np.float128]:
330+
float_types = [np.float, np.float16, np.float32, np.float64]
331+
if hasattr(np, 'float128'):
332+
float_types.append(np.float128)
333+
for np_float_type in float_types:
331334
data_frame = pd.DataFrame([15.5], index=[now], columns=['level']).astype(np_float_type)
332335
points = data_frame_to_list_of_points(data_frame=data_frame,
333336
data_frame_measurement_name='h2o',

0 commit comments

Comments
 (0)