I have a idaydf.index that I am trying to localize timezone
DatetimeIndex(['2022-10-24 16:00:00', '2022-10-24 16:15:00',
...
'2023-06-16 21:58:00', '2023-06-16 22:00:00'],
dtype='datetime64[ns]', name='DateTime', length=9012, freq=None)
with
idaydf.index = idaydf.index.tz_localize(LOCAL_TZ)
where LOCAL_TZ is
_PytzShimTimezone(zoneinfo.ZoneInfo(key='Europe/London'), 'Europe/London')
I get this error:
*** AttributeError: 'NoneType' object has no attribute 'total_seconds'
I have these versions:
python3-3.11.3
pandas-1.5.3
pytz-2023.3-1
tzlocal 4.2
How to fix?
You could use the string representation of the timezone object to decouple. That way,
LOCAL_TZcan switch to zoneinfo without crashing your codetry/exceptsEx:
Btw.
tzlocaloffers a way to directly obtain the IANA tz name as a string, which might make things even easier here -This works already with tzlocal version 4.2