Skip to content

perf: Prefer datetime.fromisoformat over dateutil.parse in Python 3.11+ #657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## 1.44.0 [unreleased]

### Features
1. [#657](https://github.com/influxdata/influxdb-client-python/pull/657): Prefer datetime.fromisoformat over dateutil.parse in Python 3.11+

## 1.43.0 [2024-05-17]

### Bug Fixes
Expand Down
9 changes: 7 additions & 2 deletions influxdb_client/client/util/date_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Utils to get right Date parsing function."""
import datetime
from sys import version_info
import threading
from datetime import timezone as tz

Expand Down Expand Up @@ -78,7 +79,8 @@ def get_date_helper() -> DateHelper:
"""
Return DateHelper with proper implementation.

If there is a 'ciso8601' than use 'ciso8601.parse_datetime' else use 'dateutil.parse'.
If there is a 'ciso8601' than use 'ciso8601.parse_datetime' else
use 'datetime.fromisoformat' (Python >= 3.11) or 'dateutil.parse' (Python < 3.11).
"""
global date_helper
if date_helper is None:
Expand All @@ -90,7 +92,10 @@ def get_date_helper() -> DateHelper:
import ciso8601
_date_helper.parse_date = ciso8601.parse_datetime
except ModuleNotFoundError:
_date_helper.parse_date = parser.parse
if (version_info.major, version_info.minor) >= (3, 11):
_date_helper.parse_date = datetime.datetime.fromisoformat
else:
_date_helper.parse_date = parser.parse
date_helper = _date_helper

return date_helper