Skip to content

Commit e360e61

Browse files
fix: timezone offset with old pytz and pandas
It seems that older pandas and pytz distributions (for example, ones from Debian 10 deb repositories) are prone to issues when pytz timezone offset ignores current datetime value [1]. Using explicit localize is both valid in modern version and fixes the bug for older ones. 1. https://stackoverflow.com/questions/11473721/weird-timezone-issue-with-pytz Part of #198
1 parent c983db6 commit e360e61

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
211211
- Puting test files in pip package (#238).
212212
- Make connection close idempotent (#250).
213213
- readthedocs version (#255).
214+
- timezone offset with old pytz and pandas (#198).
214215

215216
## 0.9.0 - 2022-06-20
216217

Diff for: Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ rpm-dist-check:
6464

6565
.PHONY: deb-changelog-entry
6666
deb-changelog-entry:
67-
[email protected] dch --distribution unstable \
67+
[email protected] dch --distribution unstable -b \
6868
--package "python3-tarantool" \
6969
--newversion $$(python3 setup.py --version) \
7070
"Nightly build"

Diff for: tarantool/msgpack_ext/types/datetime.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ def __init__(self, *, timestamp=None, year=None, month=None,
291291
datetime = pandas.to_datetime(timestamp, unit='s')
292292

293293
if not timestamp_since_utc_epoch:
294-
self._datetime = datetime.replace(tzinfo=tzinfo)
294+
self._datetime = datetime.tz_localize(tzinfo)
295295
else:
296-
self._datetime = datetime.replace(tzinfo=pytz.UTC).tz_convert(tzinfo)
296+
self._datetime = datetime.tz_localize(pytz.UTC).tz_convert(tzinfo)
297297
else:
298298
if nsec is not None:
299299
microsecond = nsec // NSEC_IN_MKSEC
@@ -306,7 +306,7 @@ def __init__(self, *, timestamp=None, year=None, month=None,
306306
year=year, month=month, day=day,
307307
hour=hour, minute=minute, second=sec,
308308
microsecond=microsecond,
309-
nanosecond=nanosecond, tzinfo=tzinfo)
309+
nanosecond=nanosecond).tz_localize(tzinfo)
310310

311311
def _interval_operation(self, other, sign=1):
312312
"""

0 commit comments

Comments
 (0)