We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
pytz
1 parent 2db3afc commit 22a8707Copy full SHA for 22a8707
CHANGELOG.md
@@ -3,6 +3,9 @@
3
### Features
4
1. [#440](https://github.com/influxdata/influxdb-client-python/pull/440): Add possibility to specify timestamp column and its timezone [DataFrame]
5
6
+### Dependencies
7
+1. [#449](https://github.com/influxdata/influxdb-client-python/pull/449): Remove `pytz` library
8
+
9
## 1.29.1 [2022-05-23]
10
11
### Bug Fixes
README.rst
@@ -452,7 +452,6 @@ The batching is configurable by ``write_options``\ :
452
453
import pandas as pd
454
import rx
455
- from pytz import UTC
456
from rx import operators as ops
457
458
from influxdb_client import InfluxDBClient, Point, WriteOptions
@@ -512,7 +511,7 @@ The batching is configurable by ``write_options``\ :
512
511
"""
513
Write Pandas DataFrame
514
515
- _now = datetime.now(UTC)
+ _now = datetime.utcnow()
516
_data_frame = pd.DataFrame(data=[["coyote_creek", 1.0], ["coyote_creek", 2.0]],
517
index=[_now, _now + timedelta(hours=1)],
518
columns=["location", "water_level"])
@@ -824,11 +823,11 @@ If you would like to import gigabytes of data then use our multiprocessing examp
824
823
825
For better performance is sometimes useful directly create a LineProtocol to avoid unnecessary escaping overhead:
826
827
- # from pytz import UTC
+ # from datetime import timezone
828
# import ciso8601
829
# from influxdb_client.client.write.point import EPOCH
830
#
831
- # time = (UTC.localize(ciso8601.parse_datetime(row["Date"])) - EPOCH).total_seconds() * 1e9
+ # time = (ciso8601.parse_datetime(row["Date"]).replace(tzinfo=timezone.utc) - EPOCH).total_seconds() * 1e9
832
# return f"financial-analysis,type=vix-daily" \
833
# f" close={float(row['VIX Close'])},high={float(row['VIX High'])},low={float(row['VIX Low'])},open={float(row['VIX Open'])} " \
834
# f" {int(time)}"
examples/import_data_set.py
@@ -35,11 +35,11 @@ def parse_row(row: OrderedDict):
35
36
37
38
39
40
41
42
43
44
45
examples/query_from_file.py
@@ -3,9 +3,7 @@
import calendar
import random
-from datetime import datetime, timedelta
-
-from pytz import UTC
+from datetime import datetime, timedelta, timezone
from influxdb_client import InfluxDBClient, Point
from influxdb_client.client.write_api import SYNCHRONOUS
@@ -18,7 +16,7 @@
18
16
19
17
20
_points = []
21
- now = datetime.now(UTC).replace(hour=13, minute=20, second=15, microsecond=0)
+ now = datetime.now(timezone.utc).replace(hour=13, minute=20, second=15, microsecond=0)
22
for i in range(50):
23
_point = Point("weather")\
24
.tag("location", "New York")\
influxdb_client/client/util/date_utils.py
@@ -1,16 +1,16 @@
1
"""Utils to get right Date parsing function."""
2
import datetime
+from datetime import timezone as tz
from dateutil import parser
date_helper = None
class DateHelper:
"""DateHelper to groups different implementations of date operations."""
12
13
- def __init__(self, timezone: datetime.tzinfo = UTC) -> None:
+ def __init__(self, timezone: datetime.tzinfo = tz.utc) -> None:
14
15
Initialize defaults.
@@ -51,7 +51,7 @@ def to_utc(self, value: datetime):
51
if not value.tzinfo:
52
return self.to_utc(value.replace(tzinfo=self.timezone))
53
else:
54
- return value.astimezone(UTC)
+ return value.astimezone(tz.utc)
55
56
57
def get_date_helper() -> DateHelper:
influxdb_client/client/write/point.py
@@ -2,16 +2,14 @@
import math
from builtins import int
from decimal import Decimal
from numbers import Integral
from influxdb_client.client.util.date_utils import get_date_helper
from influxdb_client.domain.write_precision import WritePrecision
-EPOCH = UTC.localize(datetime.utcfromtimestamp(0))
+EPOCH = datetime.utcfromtimestamp(0).replace(tzinfo=timezone.utc)
DEFAULT_WRITE_PRECISION = WritePrecision.NS
notebooks/stock_predictions_import_data.py
@@ -5,11 +5,11 @@
from collections import OrderedDict
from csv import DictReader
+from datetime import timezone
import ciso8601
import requests
from influxdb_client import InfluxDBClient, WriteOptions
@@ -41,7 +41,7 @@ def parse_row(row: OrderedDict):
if _progress % 10000 == 0:
print(_progress)
- time = (UTC.localize(ciso8601.parse_datetime(row["date"])) - EPOCH).total_seconds() * 1e9
+ time = (ciso8601.parse_datetime(row["date"]).replace(tzinfo=timezone.utc) - EPOCH).total_seconds() * 1e9
46
return f'financial-analysis,symbol={row["symbol"]} ' \
47
f'close={row["close"]},high={row["high"]},low={row["low"]},open={row["open"]} ' \
setup.py
@@ -9,8 +9,7 @@
'certifi >= 14.05.14',
'python_dateutil >= 2.5.3',
'setuptools >= 21.0.0',
- 'urllib3 >= 1.26.0',
- 'pytz>=2019.1'
+ 'urllib3 >= 1.26.0'
]
test_requires = [
tests/test_DateHelper.py
@@ -3,7 +3,7 @@
import unittest
from datetime import datetime, timezone
-from pytz import UTC, timezone
+from dateutil import tz
from influxdb_client.client.util.date_utils import DateHelper
@@ -12,11 +12,11 @@ class DateHelperTest(unittest.TestCase):
def test_to_utc(self):
date = DateHelper().to_utc(datetime(2021, 4, 29, 20, 30, 10, 0))
- self.assertEqual(datetime(2021, 4, 29, 20, 30, 10, 0, UTC), date)
+ self.assertEqual(datetime(2021, 4, 29, 20, 30, 10, 0, timezone.utc), date)
def test_to_utc_different_timezone(self):
- date = DateHelper(timezone=timezone('ETC/GMT+2')).to_utc(datetime(2021, 4, 29, 20, 30, 10, 0))
- self.assertEqual(datetime(2021, 4, 29, 22, 30, 10, 0, UTC), date)
+ date = DateHelper(timezone=tz.gettz('ETC/GMT+2')).to_utc(datetime(2021, 4, 29, 20, 30, 10, 0))
+ self.assertEqual(datetime(2021, 4, 29, 22, 30, 10, 0, timezone.utc), date)
if __name__ == '__main__':
tests/test_DeleteApi.py
@@ -1,6 +1,4 @@
-from datetime import datetime
+from datetime import datetime, timezone
from influxdb_client import PermissionResource, Permission, InfluxDBClient, Point
@@ -78,7 +76,7 @@ def test_delete_org_parameters_types(self):
78
76
def test_start_stop_types(self):
79
77
starts_stops = [
80
("1970-01-01T00:00:00.000000001Z", "1970-01-01T00:00:00.000000012Z"),
81
- (datetime(1970, 1, 1, 0, 0, 0, 0, UTC), datetime(1970, 1, 1, 0, 0, 0, 1, UTC)),
+ (datetime(1970, 1, 1, 0, 0, 0, 0, timezone.utc), datetime(1970, 1, 1, 0, 0, 0, 1, timezone.utc)),
82
(datetime(1970, 1, 1, 0, 0, 0, 0), datetime(1970, 1, 1, 0, 0, 0, 1))
83
84
for start_stop in starts_stops:
0 commit comments