Skip to content

DOC: update the DatetimeIndex.tz_convert(tz) docstring #20096

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
Changes from 3 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: 29 additions & 5 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1904,24 +1904,48 @@ def delete(self, loc):

def tz_convert(self, tz):
"""
Convert tz-aware DatetimeIndex from one time zone to another (using
pytz/dateutil)
Convert tz-aware DatetimeIndex from one
time zone to another.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put this on one line? (I think it should fit within 80 chars)


When using DatetimeIndex providing with timezone this method
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a cumbersome sentence and is pretty duplicative of the above, I would remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I regret the auto typing mistake, I wanted to convey that i will surely be doing it as per recommended by you.
Please pardon my Indian English.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hammadmashkoor no problem. thanks for the PR!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this extended summary is needed at all as its duplicated of the Summary.

converts tz-aware DatetimeIndex using pytz/dateutil.

Parameters
----------
tz : string, pytz.timezone, dateutil.tz.tzfile or None
Time zone for time. Corresponding timestamps would be converted to
time zone of the TimeSeries.
Time zone for time.Corresponding timestamps would be converted
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You seemed to have removed a space between the two words, which I suppose was a mistake.

to time zone of the TimeSeries.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TimeSeries -> DatetimeIndex

None will remove timezone holding UTC time.

Returns
-------
normalized : DatetimeIndex

Raises
------
-------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not needed (the line under the title can be exactly as long as the title itself)

TypeError
If DatetimeIndex is tz-naive.

See Also
--------
tz_localize : Localize tz-naive DatetimeIndex to given time zone
(using pytz/dateutil),or remove timezone from tz-aware
DatetimeIndex.

Examples
--------
>>> datetime=pd.Series(pd.date_range('20180301',periods=3))
>>> datetime
0 2018-03-01
1 2018-03-02
2 2018-03-03
dtype: datetime64[ns]

>>> datetime.dt.tz_localize('UTC').dt.tz_convert('US/Eastern')
0 2018-02-28 19:00:00-05:00
1 2018-03-01 19:00:00-05:00
2 2018-03-02 19:00:00-05:00
dtype: datetime64[ns, US/Eastern]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add an example that uses tz_convert(None) ?
It's explained at the end of this section: https://pandas.pydata.org/pandas-docs/stable/timeseries.html#working-with-time-zones

"""
tz = timezones.maybe_get_tz(tz)

Expand Down