Skip to content

Commit f744c23

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 2c942b0 commit f744c23

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

CHANGELOG.md

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

214215
## 0.9.0 - 2022-06-20
215216

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)