-
-
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
DOC: update the DatetimeIndex.tz_convert(tz) docstring #20096
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.
try to make summary more clear
tz --> timezone
Codecov Report
@@ Coverage Diff @@
## master #20096 +/- ##
=========================================
Coverage ? 91.72%
=========================================
Files ? 150
Lines ? 49156
Branches ? 0
=========================================
Hits ? 45090
Misses ? 4066
Partials ? 0
Continue to review full report at Codecov.
|
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! Added some comments
pandas/core/indexes/datetimes.py
Outdated
Convert tz-aware DatetimeIndex from one time zone to another (using | ||
pytz/dateutil) | ||
Convert tz-aware DatetimeIndex from one | ||
time zone to another. |
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 put this on one line? (I think it should fit within 80 chars)
pandas/core/indexes/datetimes.py
Outdated
@@ -1904,24 +1904,47 @@ def delete(self, loc): | |||
|
|||
def tz_convert(self, tz): | |||
""" | |||
Convert tz-aware DatetimeIndex from one time zone to another (using | |||
pytz/dateutil) | |||
Convert tz(timezone)-aware DatetimeIndex using pytz/dateutil. |
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 just use 'timezone' instead of both the abbreviation and full. You can maybe put the abbreviation and explanation in the extended summary
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 it is also fine to leave the "using pytz/dateutil." for the extended summary, as this is already quite a detail.
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. | ||
Time zone for time.Corresponding timestamps would be converted |
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 seemed to have removed a space between the two words, which I suppose was a mistake.
pandas/core/indexes/datetimes.py
Outdated
None will remove timezone holding UTC time. | ||
|
||
Returns | ||
------- | ||
normalized : DatetimeIndex | ||
|
||
Raises | ||
------ | ||
------- |
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 change is not needed (the line under the title can be exactly as long as the title itself)
pandas/core/indexes/datetimes.py
Outdated
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] |
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 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
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 you run the validate_docstrings script again?
pandas/core/indexes/datetimes.py
Outdated
Examples | ||
-------- | ||
>>> didx = pd.DatetimeIndex | ||
(start='2014-08-01 09:00', freq='H', periods=10, tz='Europe/Berlin') |
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.
periods=3
is long enough I think to illustrate the example, and will give a shorter output
pandas/core/indexes/datetimes.py
Outdated
'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) |
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 put here a small sentence explaining the example?
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 didn't realize we actually allow None here.
pandas/core/indexes/datetimes.py
Outdated
|
||
When using DatetimeIndex providing with timezone this method | ||
converts tz(timezone)-aware DatetimeIndex from one timezone | ||
to another using pytz/dateutil. |
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 remove the pytz/dateutil part here
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.
let's coordinate the text in this doc-string with #20050 which is sister operation.
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 have removed the pytz/dateutil part
pandas/core/indexes/datetimes.py
Outdated
'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) |
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 didn't realize we actually allow None here.
pandas/core/indexes/datetimes.py
Outdated
pytz/dateutil) | ||
Convert tz-aware DatetimeIndex from one time zone to another. | ||
|
||
When using DatetimeIndex providing with timezone this method |
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.
pandas/core/indexes/datetimes.py
Outdated
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. |
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.
TimeSeries -> DatetimeIndex
pandas/core/indexes/datetimes.py
Outdated
See Also | ||
-------- | ||
tz_localize : Localize tz-naive DatetimeIndex to given time zone | ||
(using pytz/dateutil), or remove timezone from tz-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.
remove using pytz/dateutil
pandas/core/indexes/datetimes.py
Outdated
'2014-08-01 11:00:00+02:00'], | ||
dtype='datetime64[ns, Europe/Berlin]', freq='H') | ||
|
||
With the `tz` parameter, we can change 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.
change the
pandas/core/indexes/datetimes.py
Outdated
'2014-08-01 05:00:00-04:00'], | ||
dtype='datetime64[ns, US/Eastern]', freq='H') | ||
|
||
With the `None` parameter, we can remove 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.
remove the timezone
pandas/core/indexes/datetimes.py
Outdated
|
||
Examples | ||
-------- | ||
>>> data=pd.DatetimeIndex(start='2014-08-01 09: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.
call this dti . (rather than data)
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 spaces around the equals
pandas/core/indexes/datetimes.py
Outdated
With the `tz` parameter, we can change the DatetimeIndex | ||
to other time zones: | ||
|
||
>>> dti.tz_convert('US/Eastern') |
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.
so THIS doesn't work (well it works but doesn't do what you want).
Create 2 example dti's here, the first with NO timezone (like you had originally), and .tz_localize('Europe/Berlin')
the second with tz='Europe/Berlin' then use .tz_localize(None)
, this shows removing 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.
In case of tz_convert(tz), do we have to use tz_localize() ?
pandas/core/indexes/datetimes.py
Outdated
'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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
'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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks..
made the required changes, please review @jreback |
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.
examples look good. some small grammer corrections.
pandas/core/indexes/datetimes.py
Outdated
pytz/dateutil) | ||
Convert tz-aware DatetimeIndex from one time zone to another. | ||
|
||
When using DatetimeIndex providing with timezone this method |
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.
pandas/core/indexes/datetimes.py
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
to time zone of the DatetimeIndex -> to this time zone.
pandas/core/indexes/datetimes.py
Outdated
|
||
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 comment
The 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
…eIndextzconvertfunc
Formatting on See Also Added tz PEP8 on example Switched to tz_convert
Made a few changes. Biggest one being changing the first example to demonstrate |
Thanks @hammadmashkoor ! |
Checklist for the pandas documentation sprint (ignore this if you are doing
an unrelated PR):
scripts/validate_docstrings.py <your-function-or-method>
git diff upstream/master -u -- "*.py" | flake8 --diff
python doc/make.py --single <your-function-or-method>
Please include the output of the validation script below between the "```" ticks:
If the validation script still gives errors, but you think there is a good reason
to deviate in this case (and there are certainly such cases), please state this
explicitly.