From 434236d5d2e2b6823064904eaf7026f0f592c37e Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Tue, 14 Jun 2022 12:46:28 +0200 Subject: [PATCH 1/2] fix: formatting nanoseconds to Flux AST --- influxdb_client/client/_base.py | 4 +++- tests/test_QueryApi.py | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/influxdb_client/client/_base.py b/influxdb_client/client/_base.py index 307f1d3e..5f1fff84 100644 --- a/influxdb_client/client/_base.py +++ b/influxdb_client/client/_base.py @@ -341,7 +341,9 @@ def _parm_to_extern_ast(value) -> Union[Expression, None]: return FloatLiteral("FloatLiteral", value) elif isinstance(value, datetime): value = get_date_helper().to_utc(value) - return DateTimeLiteral("DateTimeLiteral", value.strftime('%Y-%m-%dT%H:%M:%S.%fZ')) + nanoseconds = getattr(value, 'nanosecond', 0) + fraction = f'{(value.microsecond * 1000 + nanoseconds):09d}' + return DateTimeLiteral("DateTimeLiteral", value.strftime('%Y-%m-%dT%H:%M:%S.') + fraction + 'Z') elif isinstance(value, timedelta): _micro_delta = int(value / timedelta(microseconds=1)) if _micro_delta < 0: diff --git a/tests/test_QueryApi.py b/tests/test_QueryApi.py index 7e5e7241..b108cfe3 100644 --- a/tests/test_QueryApi.py +++ b/tests/test_QueryApi.py @@ -132,7 +132,7 @@ def test_parameter_ast(self): }, "init": { "type": "DateTimeLiteral", - "value": "2021-03-20T15:59:10.607352Z" + "value": "2021-03-20T15:59:10.607352000Z" }, "type": "VariableAssignment" }, @@ -150,7 +150,7 @@ def test_parameter_ast(self): }, "init": { "type": "DateTimeLiteral", - "value": "2021-03-20T15:59:10.607352Z" + "value": "2021-03-20T15:59:10.607352000Z" }, "type": "VariableAssignment" }, @@ -514,6 +514,22 @@ def test_profiler_mock(self): 'available': 5727718400, 'free': 35330048, 'used': 11452150784}) + def test_time_to_ast(self): + from influxdb_client.extras import pd + import dateutil.parser + + literals = [ + (pd.Timestamp('1996-02-25T21:20:00.001001231Z'), '1996-02-25T21:20:00.001001231Z'), + (dateutil.parser.parse('1996-02-25T21:20:00.001001231Z'), '1996-02-25T21:20:00.001001000Z'), + (dateutil.parser.parse('1996-02-25'), '1996-02-25T00:00:00.000000000Z'), + (datetime.datetime(2021, 5, 24, 8, 40, 44, 785000, tzinfo=timezone.utc), '2021-05-24T08:40:44.785000000Z'), + ] + + for literal in literals: + ast = QueryApi._build_flux_ast({'date': literal[0]}) + self.assertEqual('DateTimeLiteral', ast.body[0].assignment.init.type) + self.assertEqual(literal[1], ast.body[0].assignment.init.value) + if __name__ == '__main__': unittest.main() From 0897712fd25aafacdfdab5b38d7ffcca2e234fec Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Tue, 14 Jun 2022 12:50:04 +0200 Subject: [PATCH 2/2] docs: update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7500098..1ec8dafa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ ### Features 1. [#440](https://github.com/influxdata/influxdb-client-python/pull/440): Add possibility to specify timestamp column and its timezone [DataFrame] +### Bug Fixes +1. [#457](https://github.com/influxdata/influxdb-client-python/pull/457): Formatting nanoseconds to Flux AST + ### Dependencies 1. [#449](https://github.com/influxdata/influxdb-client-python/pull/449): Remove `pytz` library pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy