I want to compare the timezone of a pd.DatetimeIndex with a pytz.timezone to see if the DatetimeIndex has the expected timezone. But the comparison fails, possibly because using the tzinfo argument does not work as explained in this answer.
import pandas as pd
import pytz
import unittest
tzstr = 'Europe/Vienna'
manual_tz = pytz.timezone(tzstr)
timestamp = pd.to_datetime('2020-03-02 07:00:00+01:00').tz_convert(tzstr)
tc = unittest.TestCase()
tc.assertEqual(timestamp.tz, manual_tz)
AssertionError: <DstTzInfo 'Europe/Vienna' CET+1:00:00 STD> != <DstTzInfo 'Europe/Vienna' LMT+1:05:00 STD>
How can I check that the timezone of timestamp
is as expected? It should be the same as pytz.timezone
in my opinion, but the behavior of pytz and/or pandas makes them somehow different.
Alternative question formulation if it is not possible to make a comparison like this: What do I have to look out for, to not come across this problem any more? It did happen to me more than once already. I found a question similar to this, but having to use multiple dates to compare if the offset is always the same does not seem like the best way to.