Skip to content

DOC: mention tz_convert(None) and tz_localize(None) for dataframe or series #49691

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 4 commits into from
Nov 21, 2022
Merged
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
34 changes: 32 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10139,7 +10139,9 @@ def tz_convert(

Parameters
----------
tz : str or tzinfo object
tz : str or tzinfo object or None
Target time zone. Passing ``None`` will convert to
UTC and remove the timezone information.
axis : the axis to convert
level : int, str, default None
If axis is a MultiIndex, convert a specific level. Otherwise
Expand All @@ -10156,6 +10158,24 @@ def tz_convert(
------
TypeError
If the axis is tz-naive.

Examples
--------
Change to another time zone:

>>> s = pd.Series([1],
... index=pd.DatetimeIndex(['2018-09-15 01:30:00+02:00']))
>>> s.tz_convert('Asia/Shanghai')
2018-09-15 07:30:00+08:00 1
dtype: int64

Pass None to convert to UTC and get a tz-naive index:

>>> s = pd.Series([1],
... index=pd.DatetimeIndex(['2018-09-15 01:30:00+02:00']))
>>> s.tz_convert(None)
2018-09-14 23:30:00 1
dtype: int64
"""
axis = self._get_axis_number(axis)
ax = self._get_axis(axis)
Expand Down Expand Up @@ -10206,7 +10226,9 @@ def tz_localize(

Parameters
----------
tz : str or tzinfo
tz : str or tzinfo or None
Time zone to localize. Passing ``None`` will remove the
time zone information and preserve local time.
axis : the axis to localize
level : int, str, default None
If axis ia a MultiIndex, localize a specific level. Otherwise
Expand Down Expand Up @@ -10262,6 +10284,14 @@ def tz_localize(
2018-09-15 01:30:00+02:00 1
dtype: int64

Pass None to convert to tz-naive index and preserve local time:

>>> s = pd.Series([1],
... index=pd.DatetimeIndex(['2018-09-15 01:30:00+02:00']))
>>> s.tz_localize(None)
2018-09-15 01:30:00 1
dtype: int64

Be careful with DST changes. When there is sequential data, pandas
can infer the DST time:

Expand Down