From ed06451c43f4d841a84f548f0537f4aa1981fb77 Mon Sep 17 00:00:00 2001 From: Vladimir Filimonov Date: Wed, 15 Apr 2015 17:23:31 +0200 Subject: [PATCH] Fix of the docs for tz_conver and tz_localize --- pandas/core/generic.py | 13 +++++++++++-- pandas/tseries/index.py | 10 ++++++++++ pandas/tslib.pyx | 13 +++++++++++-- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 49c5791f6a5a4..8bd85a008f077 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3599,8 +3599,7 @@ def truncate(self, before=None, after=None, axis=None, copy=True): def tz_convert(self, tz, axis=0, level=None, copy=True): """ - Convert the axis to target time zone. If it is time zone naive, it - will be localized to the passed time zone. + Convert tz-aware axis to target time zone. Parameters ---------- @@ -3614,6 +3613,11 @@ def tz_convert(self, tz, axis=0, level=None, copy=True): Returns ------- + + Raises + ------ + TypeError + If the axis is tz-naive. """ axis = self._get_axis_number(axis) ax = self._get_axis(axis) @@ -3672,6 +3676,11 @@ def tz_localize(self, tz, axis=0, level=None, copy=True, Returns ------- + + Raises + ------ + TypeError + If the TimeSeries is tz-aware and tz is not None. """ axis = self._get_axis_number(axis) ax = self._get_axis(axis) diff --git a/pandas/tseries/index.py b/pandas/tseries/index.py index da9214198d774..7dac36a9ae5cc 100644 --- a/pandas/tseries/index.py +++ b/pandas/tseries/index.py @@ -1589,6 +1589,11 @@ def tz_convert(self, tz): Returns ------- normalized : DatetimeIndex + + Raises + ------ + TypeError + If DatetimeIndex is tz-naive. """ tz = tslib.maybe_get_tz(tz) @@ -1625,6 +1630,11 @@ def tz_localize(self, tz, ambiguous='raise'): Returns ------- localized : DatetimeIndex + + Raises + ------ + TypeError + If the DatetimeIndex is tz-aware and tz is not None. """ if self.tz is not None: if tz is None: diff --git a/pandas/tslib.pyx b/pandas/tslib.pyx index 3f04f80406fca..7580fa5489e15 100644 --- a/pandas/tslib.pyx +++ b/pandas/tslib.pyx @@ -447,6 +447,11 @@ class Timestamp(_Timestamp): Returns ------- localized : Timestamp + + Raises + ------ + TypeError + If the Timestamp is tz-aware and tz is not None. """ if ambiguous == 'infer': raise ValueError('Cannot infer offset with only one time.') @@ -471,8 +476,7 @@ class Timestamp(_Timestamp): def tz_convert(self, tz): """ - Convert Timestamp to another time zone or localize to requested time - zone + Convert tz-aware Timestamp to another time zone. Parameters ---------- @@ -483,6 +487,11 @@ class Timestamp(_Timestamp): Returns ------- converted : Timestamp + + Raises + ------ + TypeError + If Timestamp is tz-naive. """ if self.tzinfo is None: # tz naive, use tz_localize