From c1ec4caeab68a5bd00284f01704a0aeb4518a11e Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Thu, 24 Feb 2022 08:52:27 +0100 Subject: [PATCH 1/2] feat: DeleteApi uses default value from ``InfluxDBClient.org`` if org parameter is not specified --- docs/conf.py | 2 +- influxdb_client/client/bucket_api.py | 4 ++-- influxdb_client/client/delete_api.py | 23 ++++++++++++++-------- influxdb_client/client/influxdb_client.py | 4 ++-- influxdb_client/client/query_api.py | 24 +++++++++++------------ influxdb_client/client/write_api.py | 4 ++-- tests/test_DeleteApi.py | 21 ++++++++++++++++---- tests/test_WriteApiDataFrame.py | 5 ++++- 8 files changed, 55 insertions(+), 32 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 7dac0f17..87a744b3 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -31,7 +31,7 @@ def setup(app): project = 'influxdb_client' -copyright = '2019 InfluxData, Inc' +copyright = '2022 InfluxData, Inc' author = 'Robert Hajek, Jakub Bednar' autoclass_content = 'both' diff --git a/influxdb_client/client/bucket_api.py b/influxdb_client/client/bucket_api.py index bef342c0..4a3620cf 100644 --- a/influxdb_client/client/bucket_api.py +++ b/influxdb_client/client/bucket_api.py @@ -29,8 +29,8 @@ def create_bucket(self, bucket=None, bucket_name=None, org_id=None, retention_ru :param bucket_name: bucket name :param retention_rules: retention rules array or single BucketRetentionRules :param str, Organization org: specifies the organization for create the bucket; - take the ID, Name or Organization; - if it's not specified then is used default from client.org. + Take the ``ID``, ``Name`` or ``Organization``. + If not specified the default value from ``InfluxDBClient.org`` is used. :return: Bucket If the method is called asynchronously, returns the request thread. diff --git a/influxdb_client/client/delete_api.py b/influxdb_client/client/delete_api.py index 19fa8714..ef76339f 100644 --- a/influxdb_client/client/delete_api.py +++ b/influxdb_client/client/delete_api.py @@ -1,9 +1,11 @@ """Delete time series data from InfluxDB.""" from datetime import datetime +from typing import Union -from influxdb_client import DeleteService, DeletePredicateRequest +from influxdb_client import DeleteService, DeletePredicateRequest, Organization from influxdb_client.client.util.date_utils import get_date_helper +from influxdb_client.client.util.helpers import get_org_query_param class DeleteApi(object): @@ -14,15 +16,18 @@ def __init__(self, influxdb_client): self._influxdb_client = influxdb_client self._service = DeleteService(influxdb_client.api_client) - def delete(self, start: datetime, stop: object, predicate: object, bucket: str, org: str) -> None: + def delete(self, start: Union[str, datetime], stop: Union[str, datetime], predicate: str, bucket: str, + org: Union[str, Organization, None] = None) -> None: """ Delete Time series data from InfluxDB. - :param start: start time - :param stop: stop time - :param predicate: predicate - :param bucket: bucket id or name from which data will be deleted - :param org: organization id or name + :param str, datetime.datetime start: start time + :param str, datetime.datetime stop: stop time + :param str predicate: predicate + :param str bucket: bucket id or name from which data will be deleted + :param str, Organization org: specifies the organization to delete data from. + Take the ``ID``, ``Name`` or ``Organization``. + If not specified the default value from ``InfluxDBClient.org`` is used. :return: """ date_helper = get_date_helper() @@ -31,5 +36,7 @@ def delete(self, start: datetime, stop: object, predicate: object, bucket: str, if isinstance(stop, datetime): stop = date_helper.to_utc(stop) + org_param = get_org_query_param(org=org, client=self._influxdb_client, required_id=False) + predicate_request = DeletePredicateRequest(start=start, stop=stop, predicate=predicate) - return self._service.post_delete(delete_predicate_request=predicate_request, bucket=bucket, org=org) + return self._service.post_delete(delete_predicate_request=predicate_request, bucket=bucket, org=org_param) diff --git a/influxdb_client/client/influxdb_client.py b/influxdb_client/client/influxdb_client.py index e634c09f..9ab7cb77 100644 --- a/influxdb_client/client/influxdb_client.py +++ b/influxdb_client/client/influxdb_client.py @@ -37,9 +37,9 @@ def __init__(self, url, token, debug=None, timeout=10_000, enable_gzip=False, or :param timeout: HTTP client timeout setting for a request specified in milliseconds. If one number provided, it will be total request timeout. It can also be a pair (tuple) of (connection, read) timeouts. - :param enable_gzip: Enable Gzip compression for http requests. Currently only the "Write" and "Query" endpoints + :param enable_gzip: Enable Gzip compression for http requests. Currently, only the "Write" and "Query" endpoints supports the Gzip compression. - :param org: organization name (used as a default in query and write API) + :param org: organization name (used as a default in Query, Write and Delete API) :key bool verify_ssl: Set this to false to skip verifying SSL certificate when calling API from https server. :key str ssl_ca_cert: Set this to customize the certificate file to verify the peer. :key str proxy: Set this to configure the http proxy to be used (ex. http://localhost:3128) diff --git a/influxdb_client/client/query_api.py b/influxdb_client/client/query_api.py index c4e65ce4..c35a2e6f 100644 --- a/influxdb_client/client/query_api.py +++ b/influxdb_client/client/query_api.py @@ -55,8 +55,8 @@ def query_csv(self, query: str, org=None, dialect: Dialect = default_dialect, pa :param query: a Flux query :param str, Organization org: specifies the organization for executing the query; - take the ID, Name or Organization; - if it's not specified then is used default from client.org. + Take the ``ID``, ``Name`` or ``Organization``. + If not specified the default value from ``InfluxDBClient.org`` is used. :param dialect: csv dialect format :param params: bind parameters :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 :param query: a Flux query :param str, Organization org: specifies the organization for executing the query; - take the ID, Name or Organization; - if it's not specified then is used default from client.org. + Take the ``ID``, ``Name`` or ``Organization``. + If not specified the default value from ``InfluxDBClient.org`` is used. :param dialect: csv dialect format :param params: bind parameters :return: str @@ -92,8 +92,8 @@ def query(self, query: str, org=None, params: dict = None) -> List['FluxTable']: :param query: the Flux query :param str, Organization org: specifies the organization for executing the query; - take the ID, Name or Organization; - if it's not specified then is used default from client.org. + Take the ``ID``, ``Name`` or ``Organization``. + If not specified the default value from ``InfluxDBClient.org`` is used. :param params: bind parameters :return: """ @@ -115,8 +115,8 @@ def query_stream(self, query: str, org=None, params: dict = None) -> Generator[' :param query: the Flux query :param str, Organization org: specifies the organization for executing the query; - take the ID, Name or Organization; - if it's not specified then is used default from client.org. + Take the ``ID``, ``Name`` or ``Organization``. + If not specified the default value from ``InfluxDBClient.org`` is used. :param params: bind parameters :return: """ @@ -138,8 +138,8 @@ def query_data_frame(self, query: str, org=None, data_frame_index: List[str] = N :param query: the Flux query :param str, Organization org: specifies the organization for executing the query; - take the ID, Name or Organization; - if it's not specified then is used default from client.org. + Take the ``ID``, ``Name`` or ``Organization``. + If not specified the default value from ``InfluxDBClient.org`` is used. :param data_frame_index: the list of columns that are used as DataFrame index :param params: bind parameters :return: @@ -165,8 +165,8 @@ def query_data_frame_stream(self, query: str, org=None, data_frame_index: List[s :param query: the Flux query :param str, Organization org: specifies the organization for executing the query; - take the ID, Name or Organization; - if it's not specified then is used default from client.org. + Take the ``ID``, ``Name`` or ``Organization``. + If not specified the default value from ``InfluxDBClient.org`` is used. :param data_frame_index: the list of columns that are used as DataFrame index :param params: bind parameters :return: diff --git a/influxdb_client/client/write_api.py b/influxdb_client/client/write_api.py index 86245924..54a506d4 100644 --- a/influxdb_client/client/write_api.py +++ b/influxdb_client/client/write_api.py @@ -292,8 +292,8 @@ def write(self, bucket: str, org: str = None, :param str bucket: specifies the destination bucket for writes (required) :param str, Organization org: specifies the destination organization for writes; - take the ID, Name or Organization; - if it's not specified then is used default from client.org. + take the ID, Name or Organization. + If not specified the default value from ``InfluxDBClient.org`` is used. :param WritePrecision write_precision: specifies the precision for the unix timestamps within the body line-protocol. The precision specified on a Point has precedes and is use for write. diff --git a/tests/test_DeleteApi.py b/tests/test_DeleteApi.py index f11fccf5..b0ac6abd 100644 --- a/tests/test_DeleteApi.py +++ b/tests/test_DeleteApi.py @@ -60,7 +60,20 @@ def test_delete_buckets_by_name(self): start = "1970-01-01T00:00:00.000000001Z" stop = "1970-01-01T00:00:00.000000012Z" - self._delete_and_verify(start, stop) + self._delete_and_verify(start, stop, self.organization.name) + + def test_delete_org_parameters_types(self): + + orgs = [ + self.organization, + self.organization.id, + self.organization.name, + None + ] + + for org in orgs: + self._write_data() + self._delete_and_verify("1970-01-01T00:00:00.000000001Z", "1970-01-01T00:00:00.000000012Z", org) def test_start_stop_types(self): starts_stops = [ @@ -70,10 +83,10 @@ def test_start_stop_types(self): ] for start_stop in starts_stops: self._write_data() - self._delete_and_verify(start_stop[0], start_stop[1]) + self._delete_and_verify(start_stop[0], start_stop[1], self.organization.name) - def _delete_and_verify(self, start, stop): - self.delete_api.delete(start, stop, "", bucket=self.bucket.name, org=self.organization.name) + def _delete_and_verify(self, start, stop, org): + self.delete_api.delete(start, stop, "", bucket=self.bucket.name, org=org) flux_tables = self.client.query_api().query( f'from(bucket:"{self.bucket.name}") |> range(start: 1970-01-01T00:00:00.000000001Z)', org=self.organization.id) diff --git a/tests/test_WriteApiDataFrame.py b/tests/test_WriteApiDataFrame.py index 3e2d91cc..d285463d 100644 --- a/tests/test_WriteApiDataFrame.py +++ b/tests/test_WriteApiDataFrame.py @@ -327,7 +327,10 @@ def test_write_num_py_floats(self): from influxdb_client.extras import pd, np now = pd.Timestamp('2020-04-05 00:00+00:00') - for np_float_type in [np.float, np.float16, np.float32, np.float64, np.float128]: + float_types = [np.float, np.float16, np.float32, np.float64] + if hasattr(np, 'float128'): + float_types.append(np.float128) + for np_float_type in float_types: data_frame = pd.DataFrame([15.5], index=[now], columns=['level']).astype(np_float_type) points = data_frame_to_list_of_points(data_frame=data_frame, data_frame_measurement_name='h2o', From ee64a47257651c39dce47390505ce0b637011812 Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Thu, 24 Feb 2022 08:55:28 +0100 Subject: [PATCH 2/2] docs: update CHANGELOG.md --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 012bab60..e0c9a954 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,10 @@ ## 1.27.0 [unreleased] +### Features +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 + ### CI - 1. [#411](https://github.com/influxdata/influxdb-client-python/pull/411): Use new Codecov uploader for reporting code coverage +1. [#411](https://github.com/influxdata/influxdb-client-python/pull/411): Use new Codecov uploader for reporting code coverage ## 1.26.0 [2022-02-18]