Skip to content

Commit 53bc65e

Browse files
Merge pull request #9906 from vfilimonov/doc_tz_convert
Fix of the docs for tz_conver and tz_localize (fix for #9865)
2 parents 8cbb579 + ed06451 commit 53bc65e

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

pandas/core/generic.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -3599,8 +3599,7 @@ def truncate(self, before=None, after=None, axis=None, copy=True):
35993599

36003600
def tz_convert(self, tz, axis=0, level=None, copy=True):
36013601
"""
3602-
Convert the axis to target time zone. If it is time zone naive, it
3603-
will be localized to the passed time zone.
3602+
Convert tz-aware axis to target time zone.
36043603
36053604
Parameters
36063605
----------
@@ -3614,6 +3613,11 @@ def tz_convert(self, tz, axis=0, level=None, copy=True):
36143613
36153614
Returns
36163615
-------
3616+
3617+
Raises
3618+
------
3619+
TypeError
3620+
If the axis is tz-naive.
36173621
"""
36183622
axis = self._get_axis_number(axis)
36193623
ax = self._get_axis(axis)
@@ -3672,6 +3676,11 @@ def tz_localize(self, tz, axis=0, level=None, copy=True,
36723676
36733677
Returns
36743678
-------
3679+
3680+
Raises
3681+
------
3682+
TypeError
3683+
If the TimeSeries is tz-aware and tz is not None.
36753684
"""
36763685
axis = self._get_axis_number(axis)
36773686
ax = self._get_axis(axis)

pandas/tseries/index.py

+10
Original file line numberDiff line numberDiff line change
@@ -1589,6 +1589,11 @@ def tz_convert(self, tz):
15891589
Returns
15901590
-------
15911591
normalized : DatetimeIndex
1592+
1593+
Raises
1594+
------
1595+
TypeError
1596+
If DatetimeIndex is tz-naive.
15921597
"""
15931598
tz = tslib.maybe_get_tz(tz)
15941599

@@ -1625,6 +1630,11 @@ def tz_localize(self, tz, ambiguous='raise'):
16251630
Returns
16261631
-------
16271632
localized : DatetimeIndex
1633+
1634+
Raises
1635+
------
1636+
TypeError
1637+
If the DatetimeIndex is tz-aware and tz is not None.
16281638
"""
16291639
if self.tz is not None:
16301640
if tz is None:

pandas/tslib.pyx

+11-2
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,11 @@ class Timestamp(_Timestamp):
447447
Returns
448448
-------
449449
localized : Timestamp
450+
451+
Raises
452+
------
453+
TypeError
454+
If the Timestamp is tz-aware and tz is not None.
450455
"""
451456
if ambiguous == 'infer':
452457
raise ValueError('Cannot infer offset with only one time.')
@@ -471,8 +476,7 @@ class Timestamp(_Timestamp):
471476

472477
def tz_convert(self, tz):
473478
"""
474-
Convert Timestamp to another time zone or localize to requested time
475-
zone
479+
Convert tz-aware Timestamp to another time zone.
476480
477481
Parameters
478482
----------
@@ -483,6 +487,11 @@ class Timestamp(_Timestamp):
483487
Returns
484488
-------
485489
converted : Timestamp
490+
491+
Raises
492+
------
493+
TypeError
494+
If Timestamp is tz-naive.
486495
"""
487496
if self.tzinfo is None:
488497
# tz naive, use tz_localize

0 commit comments

Comments
 (0)