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 6 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
46 changes: 42 additions & 4 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1904,14 +1904,17 @@ 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.

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(timezone)-aware DatetimeIndex from one timezone
to another using pytz/dateutil.
Copy link
Contributor

Choose a reason for hiding this comment

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

you can remove the pytz/dateutil part here

Copy link
Contributor

Choose a reason for hiding this comment

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

let's coordinate the text in this doc-string with #20050 which is sister operation.

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 have removed the pytz/dateutil part


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
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
Expand All @@ -1922,6 +1925,41 @@ def tz_convert(self, tz):
------
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
Copy link
Contributor

Choose a reason for hiding this comment

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

remove using pytz/dateutil

DatetimeIndex.

Examples
--------
>>> didx = pd.DatetimeIndex
(start='2014-08-01 09:00', freq='H', periods=10, tz='Europe/Berlin')
Copy link
Member

Choose a reason for hiding this comment

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

periods=3 is long enough I think to illustrate the example, and will give a shorter output


>>> didx
DatetimeIndex(['2014-08-01 09:00:00+02:00','2014-08-01 10:00:00+02:00',
'2014-08-01 11:00:00+02:00', '2014-08-01 12:00:00+02:00',
'2014-08-01 13:00:00+02:00', '2014-08-01 14:00:00+02:00',
'2014-08-01 15:00:00+02:00', '2014-08-01 16:00:00+02:00',
'2014-08-01 17:00:00+02:00', '2014-08-01 18:00:00+02:00'],
dtype='datetime64[ns, Europe/Berlin]', freq='H')

>>> didx.tz_convert('US/Eastern')
DatetimeIndex(['2014-08-01 03:00:00-04:00','2014-08-01 04:00:00-04:00',
'2014-08-01 05:00:00-04:00', '2014-08-01 06:00:00-04:00',
'2014-08-01 07:00:00-04:00', '2014-08-01 08:00:00-04:00',
'2014-08-01 09:00:00-04:00', '2014-08-01 10:00:00-04:00',
'2014-08-01 11:00:00-04:00', '2014-08-01 12:00:00-04:00'],
dtype='datetime64[ns, US/Eastern]', freq='H')

>>> didx.tz_convert(None)
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 here a small sentence explaining the example?

Copy link
Contributor

Choose a reason for hiding this comment

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

@jorisvandenbossche didn't realize we actually allow None here.

DatetimeIndex(['2014-08-01 07:00:00','2014-08-01 08:00:00',
'2014-08-01 09:00:00', '2014-08-01 10:00:00',
'2014-08-01 11:00:00', '2014-08-01 12:00:00',
'2014-08-01 13:00:00', '2014-08-01 14:00:00',
'2014-08-01 15:00:00', '2014-08-01 16:00:00'],
dtype='datetime64[ns]', freq='H')
"""
tz = timezones.maybe_get_tz(tz)

Expand Down