-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
DOC: Updated docstring DatetimeIndex.tz_localize #20050
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 9 commits
9bd697d
ca813e6
a5a6a09
44b86cd
1fe3b34
b757763
fba3685
5e7b205
aca527e
8954ea8
67e2597
a791db1
99a846c
3fa0a2e
c81bd02
bdc839b
fa75bf5
85f6dbe
6205b61
95fcee2
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 |
---|---|---|
|
@@ -1937,8 +1937,10 @@ def tz_convert(self, tz): | |
mapping={True: 'infer', False: 'raise'}) | ||
def tz_localize(self, tz, ambiguous='raise', errors='raise'): | ||
""" | ||
Localize tz-naive DatetimeIndex to given time zone (using | ||
pytz/dateutil), or remove timezone from tz-aware DatetimeIndex | ||
Convert aware to naive. | ||
|
||
Localize timezone-naive DatetimeIndex to given time zone, | ||
or remove timezone from timezone aware 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. this is almost a duplicate of the top |
||
|
||
Parameters | ||
---------- | ||
|
@@ -1968,14 +1970,32 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): | |
.. deprecated:: 0.15.0 | ||
Attempt to infer fall dst-transition hours based on order | ||
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. You can leave this one (although it will give an error in the validation script, but you can ignore that) 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 will add this again. 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. @jorisvandenbossche why adding this back? looks leftover 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. @jreback @jorisvandenbossche I add this again or not ??????? 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. @jreback no, the deprecation is still there (the fact that the deprecation is still there is certainly a left-over, but let's remove that (both the actual deprecation and the docs) in a separate PR) @himanshuawasthi95 Yes, please add back |
||
|
||
|
||
Returns | ||
------- | ||
localized : DatetimeIndex | ||
|
||
Examples | ||
-------- | ||
In the example below, We put the date range from 01 March 2018 | ||
to 08 March 2018 & convert this to US/Eastern 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. don't say convert. this is localizing, almost like 'setting' a time-zone. |
||
|
||
>>> df = pd.date_range('2018-03-01', '2018-03-05') | ||
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. don't use df, dti is better 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. any thing else in summary section ??? |
||
>>> df | ||
DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03', | ||
'2018-03-04', '2018-03-05'], | ||
dtype='datetime64[ns]', freq='D') | ||
>>> df.tz_localize(tz='US/Eastern') | ||
DatetimeIndex(['2018-03-01 00:00:00-05:00', | ||
'2018-03-02 00:00:00-05:00', '2018-03-03 00:00:00-05:00', | ||
'2018-03-04 00:00:00-05:00', '2018-03-05 00:00:00-05:00'], | ||
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. showing the reverse example is also useful, IOW 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. @jreback when I add another example it shows error how I add that example in the docstring 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.
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. @jreback @jorisvandenbossche I made required change. |
||
dtype='datetime64[ns, US/Eastern]', freq='D') | ||
|
||
Raises | ||
------ | ||
TypeError | ||
If the DatetimeIndex is tz-aware and tz is not 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. I think we don't leave this line here, the validation script probably complains. |
||
""" | ||
if self.tz is not None: | ||
if tz is None: | ||
|
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.
Localize a tz-naive DatetimeIndex to tz-aware DatetimeIndex
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.
@jreback
can I add this line in extended summary :
tz_localize() takes a naive datetime object and interprets it as if it is in that timezone. It does not move the time to another timezone. tz_localize function helps to switch b/w time zone aware and time zone unaware objects.
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.
interprets -> sets it in that timezone with the current timestamps.
not sure this last line is necessary
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.
@jreback If it is give more clearity then It is okey other wise I can remove ??????