-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
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
Changes from 10 commits
b062d66
82c6546
d16d9ef
2179e2d
74ba82a
4f7a570
7a003de
fac2544
236e00b
1b56342
f8e4024
c136136
3d9b5b5
1f0adfc
ff00665
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
converts tz(timezone)-aware DatetimeIndex from one timezone | ||
to another. | ||
|
||
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 DatetimeIndex. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to time zone of the DatetimeIndex -> to this time zone. |
||
None will remove timezone holding UTC time. | ||
|
||
Returns | ||
|
@@ -1922,6 +1925,48 @@ def tz_convert(self, tz): | |
------ | ||
TypeError | ||
If DatetimeIndex is tz-naive. | ||
|
||
See Also | ||
-------- | ||
tz_localize : Localize tz-naive DatetimeIndex to given time zone, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to a given time zone or remove timezone from a tz-aware DatetimeIndex |
||
or remove timezone from tz-aware DatetimeIndex. | ||
|
||
Examples | ||
-------- | ||
With the `tz` parameter, we can change the DatetimeIndex | ||
to other time zones: | ||
|
||
>>> dti = pd.DatetimeIndex(start='2014-08-01 09:00', | ||
... freq='H', periods=3) | ||
|
||
>>> dti | ||
DatetimeIndex(['2014-08-01 09:00:00', | ||
'2014-08-01 10:00:00', | ||
'2014-08-01 11:00:00'], | ||
dtype='datetime64[ns]', freq='H') | ||
|
||
>>> dti.tz_localize('Europe/Berlin').tz_convert('US/Eastern') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't use tz_convert here, this is about the tz_localize doc-string There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
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'], | ||
dtype='datetime64[ns, US/Eastern]', freq='H') | ||
|
||
With the `None` parameter, we can remove the timezone: | ||
|
||
>>> dti = pd.DatetimeIndex(start='2014-08-01 09:00',freq='H', | ||
... periods=3, tz='Europe/Berlin') | ||
|
||
>>> dti | ||
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'], | ||
dtype='datetime64[ns, Europe/Berlin]', freq='H') | ||
|
||
>>> dti.tz_convert(None) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes this is correct There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks.. |
||
DatetimeIndex(['2014-08-01 07:00:00', | ||
'2014-08-01 08:00:00', | ||
'2014-08-01 09:00:00'], | ||
dtype='datetime64[ns]', freq='H') | ||
""" | ||
tz = timezones.maybe_get_tz(tz) | ||
|
||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.