-
-
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
Conversation
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.
Thanks for the PR! I added a first round of comments
pandas/core/indexes/datetimes.py
Outdated
pytz/dateutil), or remove timezone from tz-aware DatetimeIndex | ||
DatetimeIndex.tz_localize used for Localize tz-naive DatetimeIndex. | ||
|
||
tz_localize method is use to convert naive DatetimeIndex into any other localize |
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.
Your indentation is one space off (this line should be indented the same as the first line of the docstring)
pandas/core/indexes/datetimes.py
Outdated
@@ -1937,15 +1937,18 @@ 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 | |||
DatetimeIndex.tz_localize used for Localize tz-naive 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.
We should try to avoid to repeat the name of the method in the beginning of this summary line. What do you think of "Localize a tz-naive DatetimeIndex" ?
At the same time, we could try to make this even clearer. For example use "timezone" instead of "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.
okey sure
pandas/core/indexes/datetimes.py
Outdated
|
||
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. | ||
None will remove timezone holding local time. | ||
None will remove timezone holding local time |
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.
Please leave this final '.' (the updated validation script will also give a message about this)
pandas/core/indexes/datetimes.py
Outdated
|
||
Returns | ||
------- | ||
localized : DatetimeIndex | ||
|
||
Examples | ||
-------- |
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.
same comment here about the indentation (it seems you are mixing tabs and spaces. It is best to configure your editor to introduce 4 spaces when you do tab)
pandas/core/indexes/datetimes.py
Outdated
In the example below, We put the date range from 01 March 2018 to 08 March 2018 | ||
& convert this to US/Eastern Time zone | ||
|
||
>>> import pandas as pd |
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.
The import of pandas is not needed (check https://python-sprints.github.io/pandas/guide/pandas_docstring.html#conventions-for-the-examples)
typescript
Outdated
@@ -0,0 +1,135 @@ | |||
Script started on 2018-03-06 11:15:57+0530 | |||
[1m[7m#[27m[1m[0m ]2;root@localhost: /home/ihackpy/Panda/pandas-dir]1;..da/pandas-dir[0m[27m[24m[J[01;32m➜ [36mpandas-dir[00m [01;34mgit:([31mdocstringhead[34m) [33m✗[00m [K[?1h=[?2004hlls[?1l>[?2004l | |||
]2;ls --color=tty]1;lsappveyor.yml [0m[01;34mconda.recipe[0m [01;34mpandas[0m setup.cfg [01;32mtest.sh[0m |
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.
Can you remove this file again?
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.
Sorry I don't know HOw this file added sorry for the inconvenience
pandas/core/indexes/datetimes.py
Outdated
Raises | ||
------ | ||
TypeError | ||
If the DatetimeIndex is tz-aware and tz is not None. | ||
If the DatetimeIndex is tz-aware and tz is not 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.
Same here: please keep the '.'
Can you do a check of PEP8 with running |
Codecov Report
@@ Coverage Diff @@
## master #20050 +/- ##
==========================================
- Coverage 91.71% 91.7% -0.02%
==========================================
Files 150 150
Lines 49112 49122 +10
==========================================
Hits 45045 45045
- Misses 4067 4077 +10
Continue to review full report at Codecov.
|
pandas/core/indexes/datetimes.py
Outdated
@@ -1937,8 +1937,11 @@ 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 | |||
DatetimeIndex.tz_localize used for Localize tz-naive 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.
used to localize a tz-aware DatetimeIndex to tz-naive
pandas/core/indexes/datetimes.py
Outdated
pytz/dateutil), or remove timezone from tz-aware DatetimeIndex | ||
DatetimeIndex.tz_localize used for Localize tz-naive DatetimeIndex. | ||
|
||
tz_localize method is use to convert naive DatetimeIndex into any other |
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.
tz-aware -> tz-naive
Hello @himanshuawasthi95! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on March 14, 2018 at 08:54 Hours UTC |
@himanshuawasthi95 You are still mixing tabs and spaces. Please try to fix that first. |
Locally showing perfect I use vim for editing but don't know when I push code it shows wrong indentation is any tool which help me to remove this issue |
I am not familiar with vim myself, but you will somehow have to say to vim that tabs should not be introduces as tabs but as 4 spaces (it may 'look' good, but that doesn't mean it is not mixing tabs and spaces). See eg https://stackoverflow.com/questions/1878974/redefine-tab-as-4-spaces |
Or also see the second answer in https://stackoverflow.com/questions/426963/replace-tab-with-spaces-in-vim |
I am afraid it is not yet solved. |
Tabs/spaces issues seems to be solved! |
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.
Can you add an example for the None
behaviour as well? (removing the timezone)
pandas/core/indexes/datetimes.py
Outdated
@@ -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 Datetime index to TimeZone naive Datetime index. |
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.
"Datetime index" -> DatetimeIndex
"TimeZone" -> time zone
And it is the other way around: you now say "convert aware to naive", but it is "localize naive to aware"
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.
okey sure
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.
@jorisvandenbossche can you illustrate more "Can you add an example for the None behaviour as well? (removing the timezone)"
pandas/core/indexes/datetimes.py
Outdated
@@ -1964,18 +1966,32 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): | |||
|
|||
.. versionadded:: 0.19.0 | |||
|
|||
infer_dst : boolean, default False | |||
.. 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 comment
The 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 comment
The 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 comment
The 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 comment
The 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 comment
The 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
pandas/core/indexes/datetimes.py
Outdated
>>> df | ||
DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03', '2018-03-04', | ||
'2018-03-05'], | ||
dtype='datetime64[ns]', freq='D') |
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.
Can you clean up the alignment a bit here? If I run this in a console, I get this:
>>> df
DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03', '2018-03-04',
'2018-03-05'],
dtype='datetime64[ns]', freq='D')
Ideally it should look the same (notice the different vertical alignment with your code)
pandas/core/indexes/datetimes.py
Outdated
@@ -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. |
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.
tz_localize function helps to switch b/w time zone aware and time zone unaware objects.
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 ??????
pandas/core/indexes/datetimes.py
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
this is almost a duplicate of the top
pandas/core/indexes/datetimes.py
Outdated
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 comment
The 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.
pandas/core/indexes/datetimes.py
Outdated
>>> 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 comment
The reason will be displayed to describe this comment to others. Learn more.
showing the reverse example is also useful, IOW .tz_localize(None)
, removes the timezone and makes it tz-naive.
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 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 comment
The reason will be displayed to describe this comment to others. Learn more.
n [11]: pd.date_range('2018-03-01', '2018-03-05').tz_localize('US/Eastern').tz_localize(None)
Out[11]:
DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03', '2018-03-04',
'2018-03-05'],
dtype='datetime64[ns]', freq='D')
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 @jorisvandenbossche I made required change.
pandas/core/indexes/datetimes.py
Outdated
>>> 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 comment
The reason will be displayed to describe this comment to others. Learn more.
n [11]: pd.date_range('2018-03-01', '2018-03-05').tz_localize('US/Eastern').tz_localize(None)
Out[11]:
DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03', '2018-03-04',
'2018-03-05'],
dtype='datetime64[ns]', freq='D')
pandas/core/indexes/datetimes.py
Outdated
In the example below, We put the date range from 01 March 2018 | ||
to 08 March 2018 & convert this to US/Eastern 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
any thing else in summary section ???
pandas/core/indexes/datetimes.py
Outdated
pytz/dateutil), or remove timezone from tz-aware DatetimeIndex | ||
Localize tz-naive DatetimeIndex to tz-aware DatetimeIndex. | ||
|
||
tz_localize() takes a naive datetime object and interprets it as if 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.
takes a naive DatetimeIndex
pandas/core/indexes/datetimes.py
Outdated
>>> dti = pd.date_range('2018-03-01', '2018-03-05') | ||
>>> dti | ||
DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03', | ||
'2018-03-04', '2018-03-05'], dtype='datetime64[ns]', freq='D') |
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.
can you add a blank line between cases
pandas/core/indexes/datetimes.py
Outdated
'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'], | ||
dtype='datetime64[ns, US/Eastern]', freq='D') | ||
>>> dti.tz_localize(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.
this last won't work, you need to do
dti.tz_localize('US/Eastern').tz_localize(None)
, which gets you back the original
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.
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.
it works but its not very useful. The point is to take a tz-aware, IOW some you previously used tz_localize
on, or just constructed directly and the remove the tz.
How about you construct a new dti with a tz (IOW pass directly to date_range
), then use .tz_localize(None)
on 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.
@jreback both gives same result
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.
oh K Will do that
@jreback i changes example as required |
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.
Looks good, added some comments.
Also, in the extended summary, I'd avoid repeating the name of the method at the beginning of each parameter.
In the ambigous parameter, the accepted values should be in curly brackets (except bool-ndarray), and include 'raise'.
Btw, no need to add comments to ask for review when you push new changes. github notifies reviewers when you push.
pandas/core/indexes/datetimes.py
Outdated
@@ -1985,23 +1985,20 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): | |||
we perform reverse operation where we remove tize zone & make 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.
Can you just leave the type in Returns
(so, get rid of the "localized" name). Also, a short explanation on what is returned would be useful.
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.
@datapythonista
I'm understand that I have to remove localized from return section & write like this :
Returns
DatetimeIndex
or I should write some explanation on returns section like this:
Returns
Some Explanation
I'm confused about 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.
and parameter ambiguous : {'infer', 'NaT', default 'raise'}, bool-ndarray . write like this ???
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.
For return, first line as you say, then another line with explanation. You can check the first example here:
https://python-sprints.github.io/pandas/guide/pandas_docstring.html#section-4-returns-or-yields.
For parameter, I didn't see a case exactly like this before, but for the convention I'd say something like:
{'raise', 'infer', 'NaT'} or bool array-like, default 'raise'
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.
is there any change with summary & with example section
pandas/core/indexes/datetimes.py
Outdated
|
||
Out[5]: DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03', | ||
>>> dti.tz_localize('US/Eastern').tz_localize(None) | ||
DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03', | ||
'2018-03-04', '2018-03-05'], dtype='datetime64[ns]', freq='D') |
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.
More a personal opinion, but couple of things that I think would make the examples more clear:
- Use 3 dates instead of 5
- Add short sentences between commands on what's going on (e.g. "The values for the times are the same, but the index contains the timezone")
- Save the output of
dti.tz_localize(tz='US/Eastern')
so it can be reused in the last command, instead of doing to two localizations in the same line. May be namingdti
tz_naive
first, andtz_aware
later would make them more clear too.
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.
okey sure
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.
Looking great, added couple of last comments.
pandas/core/indexes/datetimes.py
Outdated
|
||
This method takes a naive DatetimeIndex object and interprets it as | ||
if it is in that timezone. It does not move the time to another | ||
timezone. |
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 found the interprets word a bit unclear. I think something like "Make a naive DatetimeIndex time zone aware, by attaching a time zone. It does not change the values."
Surely you can write it in a better way, but hopefully you see what I mean.
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.
@datapythonista hows this otherwise I'm going to co[py paste same you suggest above :)
"This method takes a naive DatetimeIndex object and make this time zone aware. It does not move the time to another timezone.
Time zone localization helps to switch b/w time zone aware and time zone unaware objects."
pandas/core/indexes/datetimes.py
Outdated
'2018-03-02 00:00:00-05:00', '2018-03-03 00:00:00-05:00'], | ||
dtype='datetime64[ns, US/Eastern]', freq='D') | ||
|
||
#localize aware time zone into naive time zone. |
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.
Sorry, that was my fault, but when I said to add comments to the examples, I didn't mean Python comments, but just the sentence. So, without the #
, in capital letters, and with a blank line after it (also the one before you already have).
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.
sure
pandas/core/indexes/datetimes.py
Outdated
DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03'], | ||
dtype='datetime64[ns]', freq='D') | ||
|
||
#localize DatetimeIndex in US?Eastern time zone. |
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.
Typo, ? instead of / in the time zone.
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.
Can you also remove the #
at the beginning of the line?
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.
oops
pandas/core/indexes/datetimes.py
Outdated
DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03'], | ||
dtype='datetime64[ns]', freq='D') | ||
|
||
#localize DatetimeIndex in US?Eastern time zone. |
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.
Can you also remove the #
at the beginning of the line?
pandas/core/indexes/datetimes.py
Outdated
|
||
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. | ||
None will remove timezone holding local time. | ||
ambiguous : 'infer', bool-ndarray, 'NaT', default 'raise' | ||
ambiguous : {'infer', 'NaT', default 'raise'}, bool-ndarray |
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 would make this str {'infer', 'NaT', 'raise'} or boolean array, default 'raise'
But that is probably too long, so you can do:
ambiguous : str {'infer', 'NaT', 'raise'} or bool array, \
default 'raise'
- 'infer': ...
It is a bit ugly in the code, but will render OK in plain text docstring and in html docstring.
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.
A little bit below for the "errors" keyword, can you make the type description there: errors : {'raise', 'coerce'}, default 'raise'
(so with curly braces)
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.
errors : {'raise', 'coerce'}, default 'raise'
we have to define str{'raise', 'coerce'} I thought its already understood
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.
Yes, in this case errors : {'raise', 'coerce'}, default 'raise'
is good (without the 'str')
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.
Almost there, looks good, just couple of comments for the Return and Examples sections.
pandas/core/indexes/datetimes.py
Outdated
@@ -1991,15 +1992,17 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): | |||
DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03'], |
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.
Returns
should contain a description. See the example in: https://python-sprints.github.io/pandas/guide/pandas_docstring.html#section-4-returns-or-yields
pandas/core/indexes/datetimes.py
Outdated
@@ -1991,15 +1992,17 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): | |||
DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03'], | |||
dtype='datetime64[ns]', freq='D') | |||
|
|||
#localize DatetimeIndex in US?Eastern time zone. | |||
localize DatetimeIndex in US/Eastern time zone. |
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.
The explanations of the examples need improvements. The first paragraph is outdated (end date is not the 8th). And I don't think you need to say that, it's clear from the code. So I would just get rid of it.
In this case, it should start with a capital L
. May be you can add here what you were explaining before, that dti
is naive (and also what you're already saying, that you're localizing to US/Eastern). Personally I'd rename dti
to tz_aware
, so it's more obvious.
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.
You are saying this :
In [2]: tz_aware = pd.date_range('2018-03-01', '2018-03-03')
In [3]: tz_aware
Out[3]: DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03'], dtype='datetime64[ns]', freq='D')
In [4]: tz_aware.tz_localize(tz='US/Eastern')
Out[4]:
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'],
dtype='datetime64[ns, US/Eastern]', freq='D')
In [5]: tz_aware.tz_localize(None)
Out[5]: DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03'], dtype='datetime64[ns]', freq='D')
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.
Almost. But in In [2]
that's not a tz_aware
index, it's a naive one. And in In [4]
you do want to save the output, as that's the aware one that you'll one to convert to naive in In [5]
.
Make sure that the example makes sense for you too. Reviewers can also be wrong.
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.
but thats why we added comment before where we analyse aware and naive
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 agree, but I think the variable names can still help by being descriptive, even if you explain what you're doing. Feel free to keep dti
if you prefer it over tz_naive
. But for me it's more clear to see what the example does, if the variables are more descriptive. All objects in the example could be dti
, and it doesn't help much IMO, but naming one tz_naive
and the other tz_aware
, makes it clear what every object used has.
Sorry if I'm not being able to explain what I mean clearer enough.
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 hope this commit define exactly what you want in example section
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.
sorry for disappointing you :(
pandas/core/indexes/datetimes.py
Outdated
>>> tz_aware = dti.tz_localize(tz='US/Eastern') | ||
|
||
>>> tz_aware | ||
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'], | ||
dtype='datetime64[ns, US/Eastern]', freq='D') | ||
|
||
#localize aware time zone into naive time zone. | ||
localize aware time zone into naive time zone. | ||
|
||
>>> tz_naive = tz_aware.tz_localize(None) | ||
|
||
>>> tz_naive |
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.
As you're not doing anything with tz_naive
more than displaying it, I wouldn't save it to a variable first, I'd show the output direclty.
pandas/core/indexes/datetimes.py
Outdated
>>> tz_aware = dti.tz_localize(tz='US/Eastern') | ||
|
||
>>> tz_aware | ||
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'], | ||
dtype='datetime64[ns, US/Eastern]', freq='D') | ||
|
||
#localize aware time zone into naive time zone. | ||
localize aware time zone into naive time zone. |
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.
Same as before.
pandas/core/indexes/datetimes.py
Outdated
'2018-03-02 00:00:00-05:00', '2018-03-03 00:00:00-05:00'], | ||
dtype='datetime64[ns, US/Eastern]', freq='D') | ||
|
||
Localize aware time zone into naive time zone. |
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.
"time zone aware index" instead of "aware time zone"?
pandas/core/indexes/datetimes.py
Outdated
-------- | ||
>>> tz_naive = pd.date_range('2018-03-01', '2018-03-03') | ||
|
||
>>> tz_naive |
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.
The blank line between them seems unnecessary. (also later in tz_aware)
|
||
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 comment
The 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.
pandas/core/indexes/datetimes.py
Outdated
Returns | ||
------- | ||
localized : DatetimeIndex | ||
DatetimeIndex | ||
It returns naive time or aware time |
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'd describe it more in terms of the functionality than the types. Something like "Index converted to the specified time zone." (The "It returns" seems redundant, and I think the spec requires a period at the end)
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 copied your line "index converted to the specified time zone". because It gives perfect means
The example looks much better now. Just added couple of minor comments. Sorry if I made you feel you were disappointing anyone. You're doing a great job, discussions in reviews are a normal and very beneficial part of open source. As you get more experience probably the discussions will be a bit shorter. But we've all been there (and we often are), in these PRs that require several iterations to look great. :) |
lgtm |
Thats why I love community thanks for supporting and guiding |
Thanks alot :) |
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.
Did some final edits, looks good!
@himanshuawasthi95 Thanks for the PR! |
Kindly review this docstring DatetimeIndex.tz_localize