Skip to content

Commit 025fbd0

Browse files
authored
DOC: mention tz_convert(None) and tz_localize(None) for dataframe or series (pandas-dev#49691)
1 parent 9ee3325 commit 025fbd0

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

pandas/core/generic.py

+32-2
Original file line numberDiff line numberDiff line change
@@ -10139,7 +10139,9 @@ def tz_convert(
1013910139
1014010140
Parameters
1014110141
----------
10142-
tz : str or tzinfo object
10142+
tz : str or tzinfo object or None
10143+
Target time zone. Passing ``None`` will convert to
10144+
UTC and remove the timezone information.
1014310145
axis : the axis to convert
1014410146
level : int, str, default None
1014510147
If axis is a MultiIndex, convert a specific level. Otherwise
@@ -10156,6 +10158,24 @@ def tz_convert(
1015610158
------
1015710159
TypeError
1015810160
If the axis is tz-naive.
10161+
10162+
Examples
10163+
--------
10164+
Change to another time zone:
10165+
10166+
>>> s = pd.Series([1],
10167+
... index=pd.DatetimeIndex(['2018-09-15 01:30:00+02:00']))
10168+
>>> s.tz_convert('Asia/Shanghai')
10169+
2018-09-15 07:30:00+08:00 1
10170+
dtype: int64
10171+
10172+
Pass None to convert to UTC and get a tz-naive index:
10173+
10174+
>>> s = pd.Series([1],
10175+
... index=pd.DatetimeIndex(['2018-09-15 01:30:00+02:00']))
10176+
>>> s.tz_convert(None)
10177+
2018-09-14 23:30:00 1
10178+
dtype: int64
1015910179
"""
1016010180
axis = self._get_axis_number(axis)
1016110181
ax = self._get_axis(axis)
@@ -10206,7 +10226,9 @@ def tz_localize(
1020610226
1020710227
Parameters
1020810228
----------
10209-
tz : str or tzinfo
10229+
tz : str or tzinfo or None
10230+
Time zone to localize. Passing ``None`` will remove the
10231+
time zone information and preserve local time.
1021010232
axis : the axis to localize
1021110233
level : int, str, default None
1021210234
If axis ia a MultiIndex, localize a specific level. Otherwise
@@ -10262,6 +10284,14 @@ def tz_localize(
1026210284
2018-09-15 01:30:00+02:00 1
1026310285
dtype: int64
1026410286
10287+
Pass None to convert to tz-naive index and preserve local time:
10288+
10289+
>>> s = pd.Series([1],
10290+
... index=pd.DatetimeIndex(['2018-09-15 01:30:00+02:00']))
10291+
>>> s.tz_localize(None)
10292+
2018-09-15 01:30:00 1
10293+
dtype: int64
10294+
1026510295
Be careful with DST changes. When there is sequential data, pandas
1026610296
can infer the DST time:
1026710297

0 commit comments

Comments
 (0)