2

Here's an example:

import pandas as pd

from datetime import datetime, timezone
from zoneinfo import ZoneInfo

string = '2038-04-01 09:00:00.000000'

dt = datetime.fromisoformat(string)
dt = dt.replace(tzinfo=timezone.utc)
tz = ZoneInfo('America/Boise')
converted_dt = dt.astimezone(tz)
print(converted_dt)
print(pd.Timestamp(string).tz_localize('UTC').tz_convert('America/Boise'))

This prints:

2038-04-01 03:00:00-06:00
2038-04-01 02:00:00-07:00

Why do they have different offsets?

ignoring_gravity
  • 6,677
  • 4
  • 32
  • 65
  • 1
    This might be related to time issue with year 2038 problem in computer systems. Warning is also presented in pandas documentation for those dates beyond 2038-01-18. See https://pandas.pydata.org/docs/user_guide/timeseries.html#time-zone-handling – oim Jun 14 '23 at 21:11
  • IIRC, it goes back to the fact that pandas is still using pytz, which cannot read the latest format of the IANA tz database, which means it has to load a db file which contains a Y2k38 bug. There's an [issue about this on the pytz github](https://github.com/stub42/pytz/issues/31). I don't suppose pytz will fix this since the library is deprecated; so as long as pandas stays with pytz, this bug is likely to stay. – FObersteiner Jun 15 '23 at 06:37
  • thanks - OK, got to wait for pandas to stop using pytz then – ignoring_gravity Jun 15 '23 at 07:40
  • 1
    according to the [pandas github](https://github.com/pandas-dev/pandas/issues/34916), they're waiting to drop support for Python 3.8 (don't want to use `backports.zoneinfo`). When that is done, they can move to `zoneinfo`. Sounds like this might happen still this year. – FObersteiner Jun 15 '23 at 09:19

0 Answers0