regebro / tzlocal

A Python module that tries to figure out what your local timezone is

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AttributeError when assigning a time zone to pandas Timestamp with no timezone

monstrorivas opened this issue · comments

In version tzlocal==3.0b1, I run into an AttributeError when assigning a time zone to pandas Timestamp with no timezone

It can be reproduce with the following code:

import pandas as pd
import datetime 
import tzlocal
pd_end = pd.to_datetime(datetime.datetime.now())
pd_end.tz_localize(tzlocal.get_localzone())

The same code works just fine with tzlocal==2.1 (pandas == 1.2.4 for both)

What is the error?

Oh, I see, yes, this is the API change in version 3. Version 3 uses ZoneInfo objects instead of pytz objects. If you want to use pytz, you should indeed stay with version 2.1.

Sorry for the late reply. For reference the error is:

AttributeError: 'NoneType' object has no attribute 'total_seconds'

Thank you for the information. I didn't know there was a change in the API. In that case, I can use something like this to make it work

pd_end = pd.to_datetime(datetime.datetime.now())
pd_end.tz_localize(str(tzlocal.get_localzone()))

No, it's hard to communicate that. I probably should have had a version 2.2 that logged a warning, but then again, how many people would have seen that?