def tz_validate(self): """ For a localized time zone, verify that there are no DST ambiguities (using pytz) Returns ------- result : boolean True if there are no DST ambiguities """ import pytz if self.tz is None or self.tz is pytz.utc: return True # See if there are any DST resolution problems try: lib.tz_localize(self.asi8, self.tz) except: return False return True
def tz_localize(self, tz): """ Localize tz-naive DatetimeIndex to given time zone (using pytz) Returns ------- localized : DatetimeIndex """ if self.tz is not None: raise ValueError("Already have timezone info, " "use tz_normalize to convert.") tz = tools._maybe_get_tz(tz) new_dates = lib.tz_localize(self.asi8, tz) new_dates = new_dates.view('M8[us]') new_dates = new_dates.view(self.__class__) new_dates.offset = self.offset new_dates.tz = tz new_dates.name = self.name return new_dates
def tz_normalize(self, tz): """ Convert DatetimeIndex from one time zone to another (using pytz) Returns ------- normalized : DatetimeIndex """ tz = tools._maybe_get_tz(tz) if self.tz is None: new_dates = lib.tz_localize(self.asi8, tz) else: new_dates = lib.tz_convert(self.asi8, self.tz, tz) new_dates = new_dates.view('M8[us]') new_dates = new_dates.view(type(self)) new_dates.offset = self.offset new_dates.tz = tz new_dates.name = self.name return new_dates