Skip to content

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

Merged
merged 20 commits into from
Mar 14, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
32 changes: 25 additions & 7 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

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".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okey sure


tz_localize method is use to convert naive DatetimeIndex into any other localize
Copy link
Member

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)

DatetimeIndex


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
Copy link
Member

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)

ambiguous : 'infer', bool-ndarray, 'NaT', default 'raise'
- 'infer' will attempt to infer fall dst-transition hours based on
order
Expand All @@ -1964,18 +1967,33 @@ 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
Copy link
Member

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)

Copy link
Contributor Author

@IHackPy IHackPy Mar 9, 2018

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.

Copy link
Contributor

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

Copy link
Contributor Author

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 ???????

Copy link
Member

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


Returns
-------
localized : DatetimeIndex

Examples
--------
Copy link
Member

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)

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
Copy link
Member

Choose a reason for hiding this comment

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

>>> df = pd.date_range('2018-03-01', '2018-03-08')
>>> df
DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03', '2018-03-04',
'2018-03-05', '2018-03-06', '2018-03-07', '2018-03-08'],
dtype='datetime64[ns]', freq='D')
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 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)

>>> 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', '2018-03-06 00:00:00-05:00',
'2018-03-07 00:00:00-05:00', '2018-03-08 00:00:00-05:00'],
dtype='datetime64[ns, US/Eastern]', freq='D')

Raises
------
TypeError
If the DatetimeIndex is tz-aware and tz is not None.
If the DatetimeIndex is tz-aware and tz is not None
Copy link
Member

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 '.'

"""
if self.tz is not None:
if tz is None:
Expand Down
Loading