Skip to content

Fix of the docs for tz_conver and tz_localize (fix for #9865) #9906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions pandas/tseries/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down
13 changes: 11 additions & 2 deletions pandas/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand All @@ -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
----------
Expand All @@ -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
Expand Down