I am using dataframe.index = dataframe.index.tz_localize('Iran')
to localize my Pandas dataframe datetime index. The problem is Django rises a NonExistentTimeError
.
Django setting.py
timezone is setted to my local time zone. TIME_ZONE = 'Iran'
Dataframe:
2014-08-11 12:00:00+00:00 3076.366
2014-08-11 11:45:00+00:00 3076.367
2014-08-11 11:30:00+00:00 3076.385
2014-08-11 11:15:00+00:00 3076.417
2014-08-11 11:00:00+00:00 3076.466
2014-08-11 10:45:00+00:00 3076.532
2014-08-11 10:30:00+00:00 3076.611
2014-08-11 10:15:00+00:00 3076.702
2014-08-11 10:00:00+00:00 3076.802
2014-08-11 09:45:00+00:00 3076.910
In [112]:dataframe.index.tzinfo
In [113]:<StaticTzInfo 'GMT'>
[10 rows x 1 columns]
The exception NonExistentTimeError
is raised from pytz when you attempt to localize a datetime
that doesn't exist in the time zone you specified.
If you're wondering how time can "not exist", consider that local time in many time zones is affected by daylight saving time. It is also occasionally affected by changes made by local governments.
In your particular case, all of the values you showed were on August 11, 2014. Iran's daylight saving time fall-back transition doesn't occur until September 21, 2014, as shown here. If one of your values was 2014-09-21 11:30:00
, then it would make sense. I can only conclude that you didn't show the actual data that caused the error. Please check your data.
Also, you should be using the full time zone name, which is 'Asia/Tehran'
. While 'Iran'
may work now, it is a backwards compatibility link only, and you should use the canonical zone name instead. See also this list on Wikipedia.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With