Skip to content

Commit 73849e7

Browse files
n-thumannbednar
andauthored
perf: Prefer datetime.fromisoformat over dateutil.parse in Python 3.11+ (influxdata#657)
* perf: Prefer datetime.fromisoformat over dateutil.parse in Python 3.11+ * docs: Add PR to changelog * docs: Update CHANGELOG.md --------- Co-authored-by: Jakub Bednář <jakub.bednar@gmail.com>
1 parent d2393e0 commit 73849e7

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## 1.44.0 [unreleased]
22

3+
### Features
4+
1. [#657](https://github.com/influxdata/influxdb-client-python/pull/657): Prefer datetime.fromisoformat over dateutil.parse in Python 3.11+
5+
36
## 1.43.0 [2024-05-17]
47

58
### Bug Fixes

influxdb_client/client/util/date_utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Utils to get right Date parsing function."""
22
import datetime
3+
from sys import version_info
34
import threading
45
from datetime import timezone as tz
56

@@ -78,7 +79,8 @@ def get_date_helper() -> DateHelper:
7879
"""
7980
Return DateHelper with proper implementation.
8081
81-
If there is a 'ciso8601' than use 'ciso8601.parse_datetime' else use 'dateutil.parse'.
82+
If there is a 'ciso8601' than use 'ciso8601.parse_datetime' else
83+
use 'datetime.fromisoformat' (Python >= 3.11) or 'dateutil.parse' (Python < 3.11).
8284
"""
8385
global date_helper
8486
if date_helper is None:
@@ -90,7 +92,10 @@ def get_date_helper() -> DateHelper:
9092
import ciso8601
9193
_date_helper.parse_date = ciso8601.parse_datetime
9294
except ModuleNotFoundError:
93-
_date_helper.parse_date = parser.parse
95+
if (version_info.major, version_info.minor) >= (3, 11):
96+
_date_helper.parse_date = datetime.datetime.fromisoformat
97+
else:
98+
_date_helper.parse_date = parser.parse
9499
date_helper = _date_helper
95100

96101
return date_helper

0 commit comments

Comments
 (0)
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