Skip to content

Commit 22a8707

Browse files
authored
chore: remove pytz library (influxdata#449)
1 parent 2db3afc commit 22a8707

File tree

13 files changed

+45
-52
lines changed

13 files changed

+45
-52
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
### Features
44
1. [#440](https://github.com/influxdata/influxdb-client-python/pull/440): Add possibility to specify timestamp column and its timezone [DataFrame]
55

6+
### Dependencies
7+
1. [#449](https://github.com/influxdata/influxdb-client-python/pull/449): Remove `pytz` library
8+
69
## 1.29.1 [2022-05-23]
710

811
### Bug Fixes

README.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,6 @@ The batching is configurable by ``write_options``\ :
452452
453453
import pandas as pd
454454
import rx
455-
from pytz import UTC
456455
from rx import operators as ops
457456
458457
from influxdb_client import InfluxDBClient, Point, WriteOptions
@@ -512,7 +511,7 @@ The batching is configurable by ``write_options``\ :
512511
"""
513512
Write Pandas DataFrame
514513
"""
515-
_now = datetime.now(UTC)
514+
_now = datetime.utcnow()
516515
_data_frame = pd.DataFrame(data=[["coyote_creek", 1.0], ["coyote_creek", 2.0]],
517516
index=[_now, _now + timedelta(hours=1)],
518517
columns=["location", "water_level"])
@@ -824,11 +823,11 @@ If you would like to import gigabytes of data then use our multiprocessing examp
824823
"""
825824
For better performance is sometimes useful directly create a LineProtocol to avoid unnecessary escaping overhead:
826825
"""
827-
# from pytz import UTC
826+
# from datetime import timezone
828827
# import ciso8601
829828
# from influxdb_client.client.write.point import EPOCH
830829
#
831-
# time = (UTC.localize(ciso8601.parse_datetime(row["Date"])) - EPOCH).total_seconds() * 1e9
830+
# time = (ciso8601.parse_datetime(row["Date"]).replace(tzinfo=timezone.utc) - EPOCH).total_seconds() * 1e9
832831
# return f"financial-analysis,type=vix-daily" \
833832
# f" close={float(row['VIX Close'])},high={float(row['VIX High'])},low={float(row['VIX Low'])},open={float(row['VIX Open'])} " \
834833
# f" {int(time)}"

examples/import_data_set.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ def parse_row(row: OrderedDict):
3535
"""
3636
For better performance is sometimes useful directly create a LineProtocol to avoid unnecessary escaping overhead:
3737
"""
38-
# from pytz import UTC
38+
# from datetime import timezone
3939
# import ciso8601
4040
# from influxdb_client.client.write.point import EPOCH
4141
#
42-
# time = (UTC.localize(ciso8601.parse_datetime(row["Date"])) - EPOCH).total_seconds() * 1e9
42+
# time = (ciso8601.parse_datetime(row["Date"]).replace(tzinfo=timezone.utc) - EPOCH).total_seconds() * 1e9
4343
# return f"financial-analysis,type=vix-daily" \
4444
# f" close={float(row['VIX Close'])},high={float(row['VIX High'])},low={float(row['VIX Low'])},open={float(row['VIX Open'])} " \
4545
# f" {int(time)}"

examples/query_from_file.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
"""
44
import calendar
55
import random
6-
from datetime import datetime, timedelta
7-
8-
from pytz import UTC
6+
from datetime import datetime, timedelta, timezone
97

108
from influxdb_client import InfluxDBClient, Point
119
from influxdb_client.client.write_api import SYNCHRONOUS
@@ -18,7 +16,7 @@
1816
"""
1917

2018
_points = []
21-
now = datetime.now(UTC).replace(hour=13, minute=20, second=15, microsecond=0)
19+
now = datetime.now(timezone.utc).replace(hour=13, minute=20, second=15, microsecond=0)
2220
for i in range(50):
2321
_point = Point("weather")\
2422
.tag("location", "New York")\

influxdb_client/client/util/date_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
"""Utils to get right Date parsing function."""
22
import datetime
3+
from datetime import timezone as tz
34

45
from dateutil import parser
5-
from pytz import UTC
66

77
date_helper = None
88

99

1010
class DateHelper:
1111
"""DateHelper to groups different implementations of date operations."""
1212

13-
def __init__(self, timezone: datetime.tzinfo = UTC) -> None:
13+
def __init__(self, timezone: datetime.tzinfo = tz.utc) -> None:
1414
"""
1515
Initialize defaults.
1616
@@ -51,7 +51,7 @@ def to_utc(self, value: datetime):
5151
if not value.tzinfo:
5252
return self.to_utc(value.replace(tzinfo=self.timezone))
5353
else:
54-
return value.astimezone(UTC)
54+
return value.astimezone(tz.utc)
5555

5656

5757
def get_date_helper() -> DateHelper:

influxdb_client/client/write/point.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
import math
44
from builtins import int
5-
from datetime import datetime, timedelta
5+
from datetime import datetime, timedelta, timezone
66
from decimal import Decimal
77
from numbers import Integral
88

9-
from pytz import UTC
10-
119
from influxdb_client.client.util.date_utils import get_date_helper
1210
from influxdb_client.domain.write_precision import WritePrecision
1311

14-
EPOCH = UTC.localize(datetime.utcfromtimestamp(0))
12+
EPOCH = datetime.utcfromtimestamp(0).replace(tzinfo=timezone.utc)
1513

1614
DEFAULT_WRITE_PRECISION = WritePrecision.NS
1715

notebooks/stock_predictions_import_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
"""
66
from collections import OrderedDict
77
from csv import DictReader
8+
from datetime import timezone
89

910
import ciso8601
1011
import requests
1112
import rx
12-
from pytz import UTC
1313
from rx import operators as ops
1414

1515
from influxdb_client import InfluxDBClient, WriteOptions
@@ -41,7 +41,7 @@ def parse_row(row: OrderedDict):
4141
if _progress % 10000 == 0:
4242
print(_progress)
4343

44-
time = (UTC.localize(ciso8601.parse_datetime(row["date"])) - EPOCH).total_seconds() * 1e9
44+
time = (ciso8601.parse_datetime(row["date"]).replace(tzinfo=timezone.utc) - EPOCH).total_seconds() * 1e9
4545

4646
return f'financial-analysis,symbol={row["symbol"]} ' \
4747
f'close={row["close"]},high={row["high"]},low={row["low"]},open={row["open"]} ' \

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
'certifi >= 14.05.14',
1010
'python_dateutil >= 2.5.3',
1111
'setuptools >= 21.0.0',
12-
'urllib3 >= 1.26.0',
13-
'pytz>=2019.1'
12+
'urllib3 >= 1.26.0'
1413
]
1514

1615
test_requires = [

tests/test_DateHelper.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import unittest
44
from datetime import datetime, timezone
55

6-
from pytz import UTC, timezone
6+
from dateutil import tz
77

88
from influxdb_client.client.util.date_utils import DateHelper
99

@@ -12,11 +12,11 @@ class DateHelperTest(unittest.TestCase):
1212

1313
def test_to_utc(self):
1414
date = DateHelper().to_utc(datetime(2021, 4, 29, 20, 30, 10, 0))
15-
self.assertEqual(datetime(2021, 4, 29, 20, 30, 10, 0, UTC), date)
15+
self.assertEqual(datetime(2021, 4, 29, 20, 30, 10, 0, timezone.utc), date)
1616

1717
def test_to_utc_different_timezone(self):
18-
date = DateHelper(timezone=timezone('ETC/GMT+2')).to_utc(datetime(2021, 4, 29, 20, 30, 10, 0))
19-
self.assertEqual(datetime(2021, 4, 29, 22, 30, 10, 0, UTC), date)
18+
date = DateHelper(timezone=tz.gettz('ETC/GMT+2')).to_utc(datetime(2021, 4, 29, 20, 30, 10, 0))
19+
self.assertEqual(datetime(2021, 4, 29, 22, 30, 10, 0, timezone.utc), date)
2020

2121

2222
if __name__ == '__main__':

tests/test_DeleteApi.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
from datetime import datetime
2-
3-
from pytz import UTC
1+
from datetime import datetime, timezone
42

53
from influxdb_client import PermissionResource, Permission, InfluxDBClient, Point
64
from influxdb_client.client.write_api import SYNCHRONOUS
@@ -78,7 +76,7 @@ def test_delete_org_parameters_types(self):
7876
def test_start_stop_types(self):
7977
starts_stops = [
8078
("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)),
79+
(datetime(1970, 1, 1, 0, 0, 0, 0, timezone.utc), datetime(1970, 1, 1, 0, 0, 0, 1, timezone.utc)),
8280
(datetime(1970, 1, 1, 0, 0, 0, 0), datetime(1970, 1, 1, 0, 0, 0, 1))
8381
]
8482
for start_stop in starts_stops:

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