From 9bd697d2d7f00a05ffe3eaedf212f5ea78a764f9 Mon Sep 17 00:00:00 2001 From: IHackPY Date: Thu, 8 Mar 2018 15:45:45 +0530 Subject: [PATCH 01/20] Updated DocString DatetimeIndex.tz_localize --- pandas/core/indexes/datetimes.py | 32 ++++++-- typescript | 135 +++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+), 7 deletions(-) create mode 100644 typescript diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 6b97ee90cd93c..06900a194556b 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -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. + + tz_localize method is use to convert naive DatetimeIndex into any other localize + 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 ambiguous : 'infer', bool-ndarray, 'NaT', default 'raise' - 'infer' will attempt to infer fall dst-transition hours based on order @@ -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 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 + + >>> import pandas as pd + >>> 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') + >>> 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 """ if self.tz is not None: if tz is None: diff --git a/typescript b/typescript new file mode 100644 index 0000000000000..40a274ca6bf07 --- /dev/null +++ b/typescript @@ -0,0 +1,135 @@ +Script started on 2018-03-06 11:15:57+0530 +# ]2;root@localhost: /home/ihackpy/Panda/pandas-dir]1;..da/pandas-dir âžœ pandas-dir git:(docstringhead) ✗ [?1h=[?2004hlls[?1l>[?2004l +]2;ls --color=tty]1;lsappveyor.yml conda.recipe pandas setup.cfg test.sh +asv_bench doc pyproject.toml setup.py tox.ini +AUTHORS.md LICENSE README.md test.bat typescript +ci LICENSES RELEASE.md test_fast.bat versioneer.py +circle.yml Makefile release_stats.sh test_fast.sh +codecov.yml MANIFEST.in scripts test_rebuild.sh +# ]2;root@localhost: /home/ihackpy/Panda/pandas-dir]1;..da/pandas-dir âžœ pandas-dir git:(docstringhead) ✗ [?1h=[?2004hccd..[?1l>[?2004l +]2;cd..]1;cd..zsh: command not found: cd.. +# ]2;root@localhost: /home/ihackpy/Panda/pandas-dir]1;..da/pandas-dir âžœ pandas-dir git:(docstringhead) ✗ [?1h=[?2004hccd ..[?1l>[?2004l +]2;cd ..]1;cd# ]2;root@localhost: /home/ihackpy/Panda]1;..ihackpy/Panda âžœ Panda [?1h=[?2004hlls[?1l>[?2004l +]2;ls --color=tty]1;lspandas-dir +# ]2;root@localhost: /home/ihackpy/Panda]1;..ihackpy/Panda âžœ Panda [?1h=[?2004hssource  .pan        s  zzsh[?1l>[?2004l +]2;zsh]1;zsh# ]2;root@localhost: /home/ihackpy/Panda]1;..ihackpy/Panda âžœ Panda [?1h=[?2004hlls[?1l>[?2004l +]2;ls --color=tty]1;lspandas-dir +# ]2;root@localhost: /home/ihackpy/Panda]1;..ihackpy/Panda âžœ Panda [?1h=[?2004hssource  ~/.pa    [?1l>[?2004l +]2;source ~]1;source# ]2;root@localhost: /home/ihackpy/Panda]1;..ihackpy/Panda âžœ Panda [?1h=[?2004hssource  . +zsh: do you wish to see all 116 possibilities (58 lines)? p  source .a panda          s  ccd ..[?1l>[?2004l +]2;cd ..]1;cd# ]2;root@localhost: /home/ihackpy]1;/home/ihackpy âžœ ihackpy [?1h=[?2004hlls[?1l>[?2004l +]2;ls --color=tty]1;lscore FirefoxSetup.tar.bz2 Panda README.md zeolearn +Desktop flask_form php_learn real_world_code zsh_font +django-outreachy mozilla.pdf Pictures Templates +Documents Music Public tensor +Downloads music-django python_form Videos +# ]2;root@localhost: /home/ihackpy]1;/home/ihackpy âžœ ihackpy [?1h=[?2004hssource  .pandasenv//spip-selfcheck.json                     +bin/ include/ lib/ pip-selfcheck.json source .pandasenv/bin/ +bin/  include/ lib/ pip-selfcheck.json source .pandasenv/bin/ +bin/  bin/   source .pandasenv/bin/ +/ +activate easy_install* pip3* python3.6@ +activate.csh easy_install-3.6* pip3.6* python-config* +activate.fish f2py* python@ wheel* +activate_this.py pip* python3*   source .pandasenv/bin/activate +activate  easy_install* pip3* python3.6@  +activate.csh easy_install-3.6* pip3.6* python-config*  +activate.fish f2py* python@ wheel*  +activate_this.py pip* python3*   source .pandasenv/bin/activate +activate  activate   source .pandasenv/bin/activate +  \ [?1l>[?2004l +]2;source .pandasenv/bin/activate]1;source# ]2;root@localhost: /home/ihackpy]1;/home/ihackpy (.pandasenv) âžœ ihackpy [?1h=[?2004hppanPda/ [?1l>[?2004l +]2;Panda]1;Panda# ]2;root@localhost: /home/ihackpy/Panda]1;..ihackpy/Panda (.pandasenv) âžœ Panda [?1h=[?2004hlls[?1l>[?2004l +]2;ls --color=tty]1;lspandas-dir +# ]2;root@localhost: /home/ihackpy/Panda]1;..ihackpy/Panda (.pandasenv) âžœ Panda [?1h=[?2004hppandas-dir/ [?1l>[?2004l +]2;pandas-dir]1;pandas-dir# ]2;root@localhost: /home/ihackpy/Panda/pandas-dir]1;..da/pandas-dir (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ [?1h=[?2004hlls[?1l>[?2004l +]2;ls --color=tty]1;lsappveyor.yml conda.recipe pandas setup.cfg test.sh +asv_bench doc pyproject.toml setup.py tox.ini +AUTHORS.md LICENSE README.md test.bat typescript +ci LICENSES RELEASE.md test_fast.bat versioneer.py +circle.yml Makefile release_stats.sh test_fast.sh +codecov.yml MANIFEST.in scripts test_rebuild.sh +# ]2;root@localhost: /home/ihackpy/Panda/pandas-dir]1;..da/pandas-dir (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ [?1h=[?2004hggit status  [?1l>[?2004l +]2;git status]1;gitOn branch docstringhead +Untracked files: + (use "git add ..." to include in what will be committed) + + typescript + +nothing added to commit but untracked files present (use "git add" to track) +# ]2;root@localhost: /home/ihackpy/Panda/pandas-dir]1;..da/pandas-dir (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ [?1h=[?2004hggit check +check-attr -- display gitattributes information +check-ignore -- debug gitignore/exclude files +check-mailmap -- show canonical names and email addresses of contacts +check-ref-format -- ensure that a reference name is well formed +checkout -- checkout branch or paths to working tree +checkout-index -- copy files from index to working directory git checkou +t ty           g  lls[?1l>[?2004l +]2;ls --color=tty]1;lsappveyor.yml conda.recipe pandas setup.cfg test.sh +asv_bench doc pyproject.toml setup.py tox.ini +AUTHORS.md LICENSE README.md test.bat typescript +ci LICENSES RELEASE.md test_fast.bat versioneer.py +circle.yml Makefile release_stats.sh test_fast.sh +codecov.yml MANIFEST.in scripts test_rebuild.sh +# ]2;root@localhost: /home/ihackpy/Panda/pandas-dir]1;..da/pandas-dir (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ [?1h=[?2004hsscr +screendump scrollkeeper-get-extended-content-list +SCREEN_NO scrollkeeper-get-index-from-docpath +script scrollkeeper-get-toc-from-docpath +scriptreplay scrollkeeper-get-toc-from-id +scripts/ scrollkeeper-install +scrollkeeper-config scrollkeeper-preinstall +scrollkeeper-extract scrollkeeper-rebuilddb +scrollkeeper-gen-seriesid scrollkeeper-uninstall +scrollkeeper-get-cl scrollkeeper-update +scrollkeeper-get-content-list   screendump +screendump  scrollkeeper-get-extended-content-list +SCREEN_NO scrollkeeper-get-index-from-docpath  +script scrollkeeper-get-toc-from-docpath  +scriptreplay scrollkeeper-get-toc-from-id  +scripts/ scrollkeeper-install  +scrollkeeper-config scrollkeeper-preinstall  +scrollkeeper-extract scrollkeeper-rebuilddb  +scrollkeeper-gen-seriesid scrollkeeper-uninstall  +scrollkeeper-get-cl scrollkeeper-update  +scrollkeeper-get-content-list   screendump +screendump  screendump   screendumpSCREEN_NO= +screendump SCREEN_NO   SCREEN_NO=script   +SCREEN_NO script   scriptreplay +script scriptreplay   scriptreplays/  +scriptreplay scripts/   scripts/ + [?1l>[?2004l +]2;scripts]1;scripts# ]2;root@localhost: /home/ihackpy/Panda/pandas-dir/scripts]1;..s-dir/scripts (.pandasenv) âžœ scripts git:(docstringhead) ✗ [?1h=[?2004hlls[?1l>[?2004l +]2;ls --color=tty]1;lsannounce.py find_commits_touching_func.py +api_rst_coverage.py find_undoc_args.py +build_dist_for_release.sh list_future_warnings.sh +build_dist.sh merge-pr.py +convert_deps.py validate_docstrings.py +# ]2;root@localhost: /home/ihackpy/Panda/pandas-dir/scripts]1;..s-dir/scripts (.pandasenv) âžœ scripts git:(docstringhead) ✗ [?1h=[?2004hvvalidlocale           v  vvalidate-validatevalidate _docstrings.py (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py °?'ÅUvalidate_docstrings.py (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py °?'ÅUvalidate_docstrings.py (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py  °?'ÅUvalidate_docstrings.py + (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py °?'ÅUvalidate_docstrings.py + (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py  °?'ÅUvalidate_docstrings.py + (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py °?'ÅUvalidate_docstrings.py + (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py  (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py  (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py  (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py  (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py  °?'ÅUvalidate_docstrings.py + (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py °?'ÅUvalidate_docstrings.py + (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py  (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py  (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py pandas.DatetimeIndex.tz_localize[?1l>[?2004l +]2;validate_docstrings.py pandas.DatetimeIndex.tz_localize]1;validate_docstrings.pyzsh: command not found: validate_docstrings.py +# ]2;root@localhost: /home/ihackpy/Panda/pandas-dir/scripts]1;..s-dir/scripts (.pandasenv) âžœ scripts git:(docstringhead) ✗ [?1h=[?2004hccd ..[?1l>[?2004l +]2;cd ..]1;cd# ]2;root@localhost: /home/ihackpy/Panda/pandas-dir]1;..da/pandas-dir (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ [?1h=[?2004hsscripts//v a alidate_docstrings.py  pandas.DatetimeIndex.tz_localize[?1l>[?2004l +]2;scripts/validate_docstrings.py pandas.DatetimeIndex.tz_localize]1;scripts/validate_docstrings.pyTraceback (most recent call last): + File "/home/ihackpy/Panda/pandas-dir/pandas/__init__.py", line 26, in + from pandas._libs import (hashtable as _hashtable, + File "/home/ihackpy/Panda/pandas-dir/pandas/_libs/__init__.py", line 4, in + from .tslib import iNaT, NaT, Timestamp, Timedelta, OutOfBoundsDatetime +ModuleNotFoundError: No module named 'pandas._libs.tslib' + +During handling of the above exception, another exception occurred: + +Traceback (most recent call last): + File "scripts/validate_docstrings.py", line 36, in + import pandas + File "/home/ihackpy/Panda/pandas-dir/pandas/__init__.py", line 35, in + "the C extensions first.".format(module)) +ImportError: C extension: No module named 'pandas._libs.tslib' not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first. +# ]2;root@localhost: /home/ihackpy/Panda/pandas-dir]1;..da/pandas-dir (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ [?1h=[?2004h (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ ÀrJ'ÅU (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗  (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ ÀrJ'ÅU (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗  ÀrJ'ÅU (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗  (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ ÀrJ'ÅU (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗  ÀrJ'ÅU (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗  ÀrJ'ÅU (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗  ÀrJ'ÅU (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗  ÀrJ'ÅU (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗  ÀrJ'ÅU (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗  ÀrJ'ÅU (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗  (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ [?2004l +# ]2;root@localhost: /home/ihackpy/Panda]1;..ihackpy/Panda âžœ Panda [?1h=[?2004h[?2004l + +Script done on 2018-03-06 12:01:54+0530 From ca813e6102045c7982ff752ec4763b6cd8e04086 Mon Sep 17 00:00:00 2001 From: IHackPY Date: Thu, 8 Mar 2018 16:44:57 +0530 Subject: [PATCH 02/20] Changes according to instruction --- pandas/core/indexes/datetimes.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 06900a194556b..3575c7246abcf 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1937,10 +1937,10 @@ def tz_convert(self, tz): mapping={True: 'infer', False: 'raise'}) def tz_localize(self, tz, ambiguous='raise', errors='raise'): """ - DatetimeIndex.tz_localize used for Localize tz-naive DatetimeIndex. - - tz_localize method is use to convert naive DatetimeIndex into any other localize - DatetimeIndex + DatetimeIndex.tz_localize used for Localize tz-naive DatetimeIndex. + + tz_localize method is use to convert naive DatetimeIndex into any other + localize DatetimeIndex Parameters @@ -1948,7 +1948,7 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): 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. ambiguous : 'infer', bool-ndarray, 'NaT', default 'raise' - 'infer' will attempt to infer fall dst-transition hours based on order @@ -1974,10 +1974,9 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): 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 + 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 >>> df = pd.date_range('2018-03-01', '2018-03-08') >>> df DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03', '2018-03-04', @@ -1993,7 +1992,7 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): Raises ------ TypeError - If the DatetimeIndex is tz-aware and tz is not None + If the DatetimeIndex is tz-aware and tz is not None. """ if self.tz is not None: if tz is None: From a5a6a097607af5109243bac79c604774c3e001a3 Mon Sep 17 00:00:00 2001 From: IHackPY Date: Thu, 8 Mar 2018 17:57:59 +0530 Subject: [PATCH 03/20] updated Docstring --- pandas/core/indexes/datetimes.py | 14 ++-- typescript | 135 ------------------------------- 2 files changed, 7 insertions(+), 142 deletions(-) delete mode 100644 typescript diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 3575c7246abcf..f0bc8f2dcc8c7 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1937,10 +1937,10 @@ def tz_convert(self, tz): mapping={True: 'infer', False: 'raise'}) def tz_localize(self, tz, ambiguous='raise', errors='raise'): """ - DatetimeIndex.tz_localize used for Localize tz-naive DatetimeIndex. + Convert aware Datetime index to TimeZone aware Datetime index. - tz_localize method is use to convert naive DatetimeIndex into any other - localize DatetimeIndex + Localize timezone-naive DatetimeIndex to given time zone , or + remove timezone from timezone aware DatetimeIndex Parameters @@ -1972,18 +1972,18 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): ------- localized : DatetimeIndex - Examples + 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 + 08 March 2018 & convert this to US/Eastern Time zone >>> df = pd.date_range('2018-03-01', '2018-03-08') >>> df - DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03', '2018-03-04', + 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') >>> df.tz_localize(tz='US/Eastern') - DatetimeIndex(['2018-03-01 00:00:00-05:00', '2018-03-02 00:00:00-05:00', + 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'], diff --git a/typescript b/typescript deleted file mode 100644 index 40a274ca6bf07..0000000000000 --- a/typescript +++ /dev/null @@ -1,135 +0,0 @@ -Script started on 2018-03-06 11:15:57+0530 -# ]2;root@localhost: /home/ihackpy/Panda/pandas-dir]1;..da/pandas-dir âžœ pandas-dir git:(docstringhead) ✗ [?1h=[?2004hlls[?1l>[?2004l -]2;ls --color=tty]1;lsappveyor.yml conda.recipe pandas setup.cfg test.sh -asv_bench doc pyproject.toml setup.py tox.ini -AUTHORS.md LICENSE README.md test.bat typescript -ci LICENSES RELEASE.md test_fast.bat versioneer.py -circle.yml Makefile release_stats.sh test_fast.sh -codecov.yml MANIFEST.in scripts test_rebuild.sh -# ]2;root@localhost: /home/ihackpy/Panda/pandas-dir]1;..da/pandas-dir âžœ pandas-dir git:(docstringhead) ✗ [?1h=[?2004hccd..[?1l>[?2004l -]2;cd..]1;cd..zsh: command not found: cd.. -# ]2;root@localhost: /home/ihackpy/Panda/pandas-dir]1;..da/pandas-dir âžœ pandas-dir git:(docstringhead) ✗ [?1h=[?2004hccd ..[?1l>[?2004l -]2;cd ..]1;cd# ]2;root@localhost: /home/ihackpy/Panda]1;..ihackpy/Panda âžœ Panda [?1h=[?2004hlls[?1l>[?2004l -]2;ls --color=tty]1;lspandas-dir -# ]2;root@localhost: /home/ihackpy/Panda]1;..ihackpy/Panda âžœ Panda [?1h=[?2004hssource  .pan        s  zzsh[?1l>[?2004l -]2;zsh]1;zsh# ]2;root@localhost: /home/ihackpy/Panda]1;..ihackpy/Panda âžœ Panda [?1h=[?2004hlls[?1l>[?2004l -]2;ls --color=tty]1;lspandas-dir -# ]2;root@localhost: /home/ihackpy/Panda]1;..ihackpy/Panda âžœ Panda [?1h=[?2004hssource  ~/.pa    [?1l>[?2004l -]2;source ~]1;source# ]2;root@localhost: /home/ihackpy/Panda]1;..ihackpy/Panda âžœ Panda [?1h=[?2004hssource  . -zsh: do you wish to see all 116 possibilities (58 lines)? p  source .a panda          s  ccd ..[?1l>[?2004l -]2;cd ..]1;cd# ]2;root@localhost: /home/ihackpy]1;/home/ihackpy âžœ ihackpy [?1h=[?2004hlls[?1l>[?2004l -]2;ls --color=tty]1;lscore FirefoxSetup.tar.bz2 Panda README.md zeolearn -Desktop flask_form php_learn real_world_code zsh_font -django-outreachy mozilla.pdf Pictures Templates -Documents Music Public tensor -Downloads music-django python_form Videos -# ]2;root@localhost: /home/ihackpy]1;/home/ihackpy âžœ ihackpy [?1h=[?2004hssource  .pandasenv//spip-selfcheck.json                     -bin/ include/ lib/ pip-selfcheck.json source .pandasenv/bin/ -bin/  include/ lib/ pip-selfcheck.json source .pandasenv/bin/ -bin/  bin/   source .pandasenv/bin/ -/ -activate easy_install* pip3* python3.6@ -activate.csh easy_install-3.6* pip3.6* python-config* -activate.fish f2py* python@ wheel* -activate_this.py pip* python3*   source .pandasenv/bin/activate -activate  easy_install* pip3* python3.6@  -activate.csh easy_install-3.6* pip3.6* python-config*  -activate.fish f2py* python@ wheel*  -activate_this.py pip* python3*   source .pandasenv/bin/activate -activate  activate   source .pandasenv/bin/activate -  \ [?1l>[?2004l -]2;source .pandasenv/bin/activate]1;source# ]2;root@localhost: /home/ihackpy]1;/home/ihackpy (.pandasenv) âžœ ihackpy [?1h=[?2004hppanPda/ [?1l>[?2004l -]2;Panda]1;Panda# ]2;root@localhost: /home/ihackpy/Panda]1;..ihackpy/Panda (.pandasenv) âžœ Panda [?1h=[?2004hlls[?1l>[?2004l -]2;ls --color=tty]1;lspandas-dir -# ]2;root@localhost: /home/ihackpy/Panda]1;..ihackpy/Panda (.pandasenv) âžœ Panda [?1h=[?2004hppandas-dir/ [?1l>[?2004l -]2;pandas-dir]1;pandas-dir# ]2;root@localhost: /home/ihackpy/Panda/pandas-dir]1;..da/pandas-dir (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ [?1h=[?2004hlls[?1l>[?2004l -]2;ls --color=tty]1;lsappveyor.yml conda.recipe pandas setup.cfg test.sh -asv_bench doc pyproject.toml setup.py tox.ini -AUTHORS.md LICENSE README.md test.bat typescript -ci LICENSES RELEASE.md test_fast.bat versioneer.py -circle.yml Makefile release_stats.sh test_fast.sh -codecov.yml MANIFEST.in scripts test_rebuild.sh -# ]2;root@localhost: /home/ihackpy/Panda/pandas-dir]1;..da/pandas-dir (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ [?1h=[?2004hggit status  [?1l>[?2004l -]2;git status]1;gitOn branch docstringhead -Untracked files: - (use "git add ..." to include in what will be committed) - - typescript - -nothing added to commit but untracked files present (use "git add" to track) -# ]2;root@localhost: /home/ihackpy/Panda/pandas-dir]1;..da/pandas-dir (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ [?1h=[?2004hggit check -check-attr -- display gitattributes information -check-ignore -- debug gitignore/exclude files -check-mailmap -- show canonical names and email addresses of contacts -check-ref-format -- ensure that a reference name is well formed -checkout -- checkout branch or paths to working tree -checkout-index -- copy files from index to working directory git checkou -t ty           g  lls[?1l>[?2004l -]2;ls --color=tty]1;lsappveyor.yml conda.recipe pandas setup.cfg test.sh -asv_bench doc pyproject.toml setup.py tox.ini -AUTHORS.md LICENSE README.md test.bat typescript -ci LICENSES RELEASE.md test_fast.bat versioneer.py -circle.yml Makefile release_stats.sh test_fast.sh -codecov.yml MANIFEST.in scripts test_rebuild.sh -# ]2;root@localhost: /home/ihackpy/Panda/pandas-dir]1;..da/pandas-dir (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ [?1h=[?2004hsscr -screendump scrollkeeper-get-extended-content-list -SCREEN_NO scrollkeeper-get-index-from-docpath -script scrollkeeper-get-toc-from-docpath -scriptreplay scrollkeeper-get-toc-from-id -scripts/ scrollkeeper-install -scrollkeeper-config scrollkeeper-preinstall -scrollkeeper-extract scrollkeeper-rebuilddb -scrollkeeper-gen-seriesid scrollkeeper-uninstall -scrollkeeper-get-cl scrollkeeper-update -scrollkeeper-get-content-list   screendump -screendump  scrollkeeper-get-extended-content-list -SCREEN_NO scrollkeeper-get-index-from-docpath  -script scrollkeeper-get-toc-from-docpath  -scriptreplay scrollkeeper-get-toc-from-id  -scripts/ scrollkeeper-install  -scrollkeeper-config scrollkeeper-preinstall  -scrollkeeper-extract scrollkeeper-rebuilddb  -scrollkeeper-gen-seriesid scrollkeeper-uninstall  -scrollkeeper-get-cl scrollkeeper-update  -scrollkeeper-get-content-list   screendump -screendump  screendump   screendumpSCREEN_NO= -screendump SCREEN_NO   SCREEN_NO=script   -SCREEN_NO script   scriptreplay -script scriptreplay   scriptreplays/  -scriptreplay scripts/   scripts/ - [?1l>[?2004l -]2;scripts]1;scripts# ]2;root@localhost: /home/ihackpy/Panda/pandas-dir/scripts]1;..s-dir/scripts (.pandasenv) âžœ scripts git:(docstringhead) ✗ [?1h=[?2004hlls[?1l>[?2004l -]2;ls --color=tty]1;lsannounce.py find_commits_touching_func.py -api_rst_coverage.py find_undoc_args.py -build_dist_for_release.sh list_future_warnings.sh -build_dist.sh merge-pr.py -convert_deps.py validate_docstrings.py -# ]2;root@localhost: /home/ihackpy/Panda/pandas-dir/scripts]1;..s-dir/scripts (.pandasenv) âžœ scripts git:(docstringhead) ✗ [?1h=[?2004hvvalidlocale           v  vvalidate-validatevalidate _docstrings.py (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py °?'ÅUvalidate_docstrings.py (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py °?'ÅUvalidate_docstrings.py (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py  °?'ÅUvalidate_docstrings.py - (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py °?'ÅUvalidate_docstrings.py - (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py  °?'ÅUvalidate_docstrings.py - (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py °?'ÅUvalidate_docstrings.py - (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py  (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py  (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py  (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py  (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py  °?'ÅUvalidate_docstrings.py - (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py °?'ÅUvalidate_docstrings.py - (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py  (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py  (.pandasenv) âžœ scripts git:(docstringhead) ✗ validate_docstrings.py pandas.DatetimeIndex.tz_localize[?1l>[?2004l -]2;validate_docstrings.py pandas.DatetimeIndex.tz_localize]1;validate_docstrings.pyzsh: command not found: validate_docstrings.py -# ]2;root@localhost: /home/ihackpy/Panda/pandas-dir/scripts]1;..s-dir/scripts (.pandasenv) âžœ scripts git:(docstringhead) ✗ [?1h=[?2004hccd ..[?1l>[?2004l -]2;cd ..]1;cd# ]2;root@localhost: /home/ihackpy/Panda/pandas-dir]1;..da/pandas-dir (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ [?1h=[?2004hsscripts//v a alidate_docstrings.py  pandas.DatetimeIndex.tz_localize[?1l>[?2004l -]2;scripts/validate_docstrings.py pandas.DatetimeIndex.tz_localize]1;scripts/validate_docstrings.pyTraceback (most recent call last): - File "/home/ihackpy/Panda/pandas-dir/pandas/__init__.py", line 26, in - from pandas._libs import (hashtable as _hashtable, - File "/home/ihackpy/Panda/pandas-dir/pandas/_libs/__init__.py", line 4, in - from .tslib import iNaT, NaT, Timestamp, Timedelta, OutOfBoundsDatetime -ModuleNotFoundError: No module named 'pandas._libs.tslib' - -During handling of the above exception, another exception occurred: - -Traceback (most recent call last): - File "scripts/validate_docstrings.py", line 36, in - import pandas - File "/home/ihackpy/Panda/pandas-dir/pandas/__init__.py", line 35, in - "the C extensions first.".format(module)) -ImportError: C extension: No module named 'pandas._libs.tslib' not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first. -# ]2;root@localhost: /home/ihackpy/Panda/pandas-dir]1;..da/pandas-dir (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ [?1h=[?2004h (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ ÀrJ'ÅU (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗  (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ ÀrJ'ÅU (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗  ÀrJ'ÅU (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗  (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ ÀrJ'ÅU (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗  ÀrJ'ÅU (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗  ÀrJ'ÅU (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗  ÀrJ'ÅU (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗  ÀrJ'ÅU (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗  ÀrJ'ÅU (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗  ÀrJ'ÅU (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗  (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ (.pandasenv) âžœ pandas-dir git:(docstringhead) ✗ [?2004l -# ]2;root@localhost: /home/ihackpy/Panda]1;..ihackpy/Panda âžœ Panda [?1h=[?2004h[?2004l - -Script done on 2018-03-06 12:01:54+0530 From 44b86cd72a49f63401b043b6cca2a19b4c7eac07 Mon Sep 17 00:00:00 2001 From: IHackPY Date: Thu, 8 Mar 2018 18:08:43 +0530 Subject: [PATCH 04/20] indentation issue --- pandas/core/indexes/datetimes.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index f0bc8f2dcc8c7..50dc6be6c755c 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1937,9 +1937,9 @@ def tz_convert(self, tz): mapping={True: 'infer', False: 'raise'}) def tz_localize(self, tz, ambiguous='raise', errors='raise'): """ - Convert aware Datetime index to TimeZone aware Datetime index. + Convert aware Datetime index to TimeZone aware Datetime index. - Localize timezone-naive DatetimeIndex to given time zone , or + Localize timezone-naive DatetimeIndex to given time zone , or remove timezone from timezone aware DatetimeIndex @@ -1972,18 +1972,18 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): ------- localized : DatetimeIndex - Examples + 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 >>> df = pd.date_range('2018-03-01', '2018-03-08') >>> df - DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03', '2018-03-04', + 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') >>> df.tz_localize(tz='US/Eastern') - DatetimeIndex(['2018-03-01 00:00:00-05:00', '2018-03-02 00:00:00-05:00', + 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'], @@ -1992,7 +1992,7 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): Raises ------ TypeError - If the DatetimeIndex is tz-aware and tz is not None. + If the DatetimeIndex is tz-aware and tz is not None. """ if self.tz is not None: if tz is None: From 1fe3b34a6fc4f2bd49b79cea45c2f11765756244 Mon Sep 17 00:00:00 2001 From: IHackPY Date: Thu, 8 Mar 2018 19:09:45 +0530 Subject: [PATCH 05/20] update Indentation --- pandas/core/indexes/datetimes.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 50dc6be6c755c..2c94212a05cec 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1937,11 +1937,10 @@ def tz_convert(self, tz): mapping={True: 'infer', False: 'raise'}) def tz_localize(self, tz, ambiguous='raise', errors='raise'): """ - Convert aware Datetime index to TimeZone aware Datetime index. - - Localize timezone-naive DatetimeIndex to given time zone , or - remove timezone from timezone aware DatetimeIndex + Convert aware Datetime index to TimeZone naive Datetime index. + Localize timezone-naive DatetimeIndex to given time zone, + or remove timezone from timezone aware DatetimeIndex. Parameters ---------- @@ -1972,18 +1971,17 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): ------- 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 + 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 - >>> df = pd.date_range('2018-03-01', '2018-03-08') - >>> df - DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03', '2018-03-04', + >>> 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') - >>> df.tz_localize(tz='US/Eastern') - DatetimeIndex(['2018-03-01 00:00:00-05:00', '2018-03-02 00:00:00-05:00', + >>> 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'], @@ -1992,7 +1990,8 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): Raises ------ TypeError - If the DatetimeIndex is tz-aware and tz is not None. + If the DatetimeIndex is tz-aware and tz is not None. + """ if self.tz is not None: if tz is None: From b757763cd4376705a0576556c970a1fb91d922c0 Mon Sep 17 00:00:00 2001 From: HimanshuAwasthi95 Date: Fri, 9 Mar 2018 11:54:53 +0530 Subject: [PATCH 06/20] Final Updated docString --- pandas/core/indexes/datetimes.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 2c94212a05cec..eee62b66b66a7 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1973,15 +1973,16 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): 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 + 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-08') >>> df - DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03', '2018-03-04', + 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') >>> df.tz_localize(tz='US/Eastern') - DatetimeIndex(['2018-03-01 00:00:00-05:00', '2018-03-02 00:00:00-05:00', + 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'], From fba3685fd502a3b6620326afe6972a1fad5bb5b6 Mon Sep 17 00:00:00 2001 From: HimanshuAwasthi95 Date: Fri, 9 Mar 2018 12:17:13 +0530 Subject: [PATCH 07/20] Final Updated Docstring --- pandas/core/indexes/datetimes.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index eee62b66b66a7..873606cd4fc1c 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1973,16 +1973,15 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): 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 + 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-08') - >>> df - DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03', '2018-03-04', + >>> 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') - >>> df.tz_localize(tz='US/Eastern') - DatetimeIndex(['2018-03-01 00:00:00-05:00', '2018-03-02 00:00:00-05:00', + >>> 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'], From 5e7b205fd50ce4cf6877eb5c14a9598e1fd83fa3 Mon Sep 17 00:00:00 2001 From: HimanshuAwasthi95 Date: Fri, 9 Mar 2018 14:06:57 +0530 Subject: [PATCH 08/20] Final Updated Docstring --- pandas/core/indexes/datetimes.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 873606cd4fc1c..7651fa5922efb 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1939,7 +1939,7 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): """ Convert aware Datetime index to TimeZone naive Datetime index. - Localize timezone-naive DatetimeIndex to given time zone, + Localize timezone-naive DatetimeIndex to given time zone, or remove timezone from timezone aware DatetimeIndex. Parameters @@ -1973,18 +1973,18 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): 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 - - >>> 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'], + 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') + >>> 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', '2018-03-06 00:00:00-05:00', - '2018-03-07 00:00:00-05:00', '2018-03-08 00:00:00-05:00'], + >>> 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'], dtype='datetime64[ns, US/Eastern]', freq='D') Raises From aca527ed3578f721ffb8111a5c48b9b0d6e5271e Mon Sep 17 00:00:00 2001 From: HimanshuAwasthi95 Date: Sat, 10 Mar 2018 00:09:10 +0530 Subject: [PATCH 09/20] added infer_dst --- pandas/core/indexes/datetimes.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 7651fa5922efb..e1670838e696a 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1937,7 +1937,7 @@ def tz_convert(self, tz): mapping={True: 'infer', False: 'raise'}) def tz_localize(self, tz, ambiguous='raise', errors='raise'): """ - Convert aware Datetime index to TimeZone naive Datetime index. + Convert aware to naive. Localize timezone-naive DatetimeIndex to given time zone, or remove timezone from timezone aware DatetimeIndex. @@ -1966,6 +1966,10 @@ 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 + Returns ------- @@ -1978,14 +1982,14 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): >>> df = pd.date_range('2018-03-01', '2018-03-05') >>> df - DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03', '2018-03-04', - '2018-03-05'], - dtype='datetime64[ns]', freq='D') + 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'], - dtype='datetime64[ns, US/Eastern]', freq='D') + dtype='datetime64[ns, US/Eastern]', freq='D') Raises ------ From 8954ea8fec0bdfdcf120bd010d52f94d551f1e63 Mon Sep 17 00:00:00 2001 From: HimanshuAwasthi95 Date: Sat, 10 Mar 2018 20:02:43 +0530 Subject: [PATCH 10/20] Add Reverse Example & update summary --- pandas/core/indexes/datetimes.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index e1670838e696a..1bc0b932b974e 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1937,10 +1937,12 @@ def tz_convert(self, tz): mapping={True: 'infer', False: 'raise'}) def tz_localize(self, tz, ambiguous='raise', errors='raise'): """ - Convert aware to naive. + Localize tz-naive DatetimeIndex to tz-aware DatetimeIndex. - Localize timezone-naive DatetimeIndex to given time zone, - or remove timezone from timezone aware DatetimeIndex. + 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. Parameters ---------- @@ -1978,18 +1980,22 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): 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 + to 08 March 2018 & localize this to US/Eastern Time zone & again + we perform reverse operation where we remove tize zone & make it + tz-naive >>> df = pd.date_range('2018-03-01', '2018-03-05') >>> df DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03', - '2018-03-04', '2018-03-05'], - dtype='datetime64[ns]', freq='D') + '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'], dtype='datetime64[ns, US/Eastern]', freq='D') + >>> df.tz_localize(None) + DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03', + '2018-03-04', '2018-03-05'], dtype='datetime64[ns]', freq='D') Raises ------ From 67e2597400c5def6ebc61ee9754f379d7ce68552 Mon Sep 17 00:00:00 2001 From: HimanshuAwasthi95 Date: Sat, 10 Mar 2018 20:15:00 +0530 Subject: [PATCH 11/20] Update df to dti --- pandas/core/indexes/datetimes.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 1bc0b932b974e..bc8fe96f9cee7 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1984,16 +1984,16 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): we perform reverse operation where we remove tize zone & make it tz-naive - >>> df = pd.date_range('2018-03-01', '2018-03-05') - >>> df + >>> 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') - >>> df.tz_localize(tz='US/Eastern') + >>> dti.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'], dtype='datetime64[ns, US/Eastern]', freq='D') - >>> df.tz_localize(None) + >>> dti.tz_localize(None) DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03', '2018-03-04', '2018-03-05'], dtype='datetime64[ns]', freq='D') From a791db131cdaf4133b01b9b830cdad79ffd99ad7 Mon Sep 17 00:00:00 2001 From: HimanshuAwasthi95 Date: Sat, 10 Mar 2018 21:17:22 +0530 Subject: [PATCH 12/20] Update final required change --- pandas/core/indexes/datetimes.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index bc8fe96f9cee7..9f1460fba83db 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1939,8 +1939,9 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): """ Localize tz-naive DatetimeIndex to tz-aware DatetimeIndex. - 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() takes a naive DatetimeIndex 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. @@ -1984,19 +1985,26 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): we perform reverse operation where we remove tize zone & make it tz-naive - >>> dti = pd.date_range('2018-03-01', '2018-03-05') - >>> dti - DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03', + In [2]: dti = pd.date_range('2018-03-01', '2018-03-05') + + In [3]: dti + + Out[3]: DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03', '2018-03-04', '2018-03-05'], dtype='datetime64[ns]', freq='D') - >>> dti.tz_localize(tz='US/Eastern') - DatetimeIndex(['2018-03-01 00:00:00-05:00', + + In [4]: dti.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', '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) - DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03', + + In [5]: dti.tz_localize('US/Eastern').tz_localize(None) + + Out[5]: DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03', '2018-03-04', '2018-03-05'], dtype='datetime64[ns]', freq='D') + Raises ------ TypeError From 99a846cbc656e7a9fdf86ca6185d3157403c5a2a Mon Sep 17 00:00:00 2001 From: HimanshuAwasthi95 Date: Sun, 11 Mar 2018 00:53:47 +0530 Subject: [PATCH 13/20] change example ipython mode to terminal mode --- pandas/core/indexes/datetimes.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 9f1460fba83db..6a6ed903ea6a0 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1985,23 +1985,20 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): we perform reverse operation where we remove tize zone & make it tz-naive - In [2]: dti = pd.date_range('2018-03-01', '2018-03-05') + >>> dti = pd.date_range('2018-03-01', '2018-03-05') - In [3]: dti - - Out[3]: DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03', + >>> dti + DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03', '2018-03-04', '2018-03-05'], dtype='datetime64[ns]', freq='D') - In [4]: dti.tz_localize(tz='US/Eastern') - - Out[4]: DatetimeIndex(['2018-03-01 00:00:00-05:00', + >>> dti.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'], dtype='datetime64[ns, US/Eastern]', freq='D') - In [5]: dti.tz_localize('US/Eastern').tz_localize(None) - - 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') From 3fa0a2ead43d0f66b867b086dc4193fbf5dda1d8 Mon Sep 17 00:00:00 2001 From: HimanshuAwasthi95 Date: Sun, 11 Mar 2018 11:22:34 +0530 Subject: [PATCH 14/20] Add comment on code --- pandas/core/indexes/datetimes.py | 33 ++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 6a6ed903ea6a0..ced7e9667756f 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1939,11 +1939,11 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): """ Localize tz-naive DatetimeIndex to tz-aware DatetimeIndex. - tz_localize() takes a naive DatetimeIndex object and interprets it as + 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. - tz_localize function helps to switch b/w time zone aware and time zone - unaware objects. + Time zone localization helps to switch b/w time zone aware and time + zone unaware objects. Parameters ---------- @@ -1951,7 +1951,7 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): 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 - 'infer' will attempt to infer fall dst-transition hours based on order - bool-ndarray where True signifies a DST time, False signifies a @@ -1976,7 +1976,7 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): Returns ------- - localized : DatetimeIndex + DatetimeIndex Examples -------- @@ -1985,21 +1985,26 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): we perform reverse operation where we remove tize zone & make it tz-naive - >>> dti = pd.date_range('2018-03-01', '2018-03-05') + >>> dti = pd.date_range('2018-03-01', '2018-03-03') >>> dti - DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03', - '2018-03-04', '2018-03-05'], dtype='datetime64[ns]', freq='D') + DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03'], + dtype='datetime64[ns]', freq='D') - >>> dti.tz_localize(tz='US/Eastern') + #localize DatetimeIndex in US?Eastern time zone. + >>> 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', - '2018-03-04 00:00:00-05:00', '2018-03-05 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') - >>> 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') + #localize aware time zone into naive time zone. + >>> tz_naive = tz_aware.tz_localize(None) + + >>> tz_naive + DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03'], + dtype='datetime64[ns]', freq='D') Raises From c81bd02c9f0a8c23b9c31a1e22a1814ebc6a9959 Mon Sep 17 00:00:00 2001 From: HimanshuAwasthi95 Date: Sun, 11 Mar 2018 19:16:12 +0530 Subject: [PATCH 15/20] Changes according guidance --- pandas/core/indexes/datetimes.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index ced7e9667756f..52b0dd42bbc9b 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1939,8 +1939,8 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): """ Localize tz-naive DatetimeIndex to tz-aware DatetimeIndex. - 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 + 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. @@ -1951,7 +1951,8 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): Time zone for time. Corresponding timestamps would be converted to time zone of the TimeSeries. None will remove timezone holding local time. - ambiguous : {'infer', 'NaT', default 'raise'}, bool-ndarray + ambiguous : str {'infer', 'NaT', 'raise'} or bool array, \ + default 'raise' - 'infer' will attempt to infer fall dst-transition hours based on order - bool-ndarray where True signifies a DST time, False signifies a @@ -1960,7 +1961,7 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): - 'NaT' will return NaT where there are ambiguous times - 'raise' will raise an AmbiguousTimeError if there are ambiguous times - errors : 'raise', 'coerce', default 'raise' + errors : {'raise', 'coerce'}, default 'raise' - 'raise' will raise a NonExistentTimeError if a timestamp is not valid in the specified timezone (e.g. due to a transition from or to DST time) @@ -1991,7 +1992,8 @@ 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. + >>> tz_aware = dti.tz_localize(tz='US/Eastern') >>> tz_aware @@ -1999,7 +2001,8 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): '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 From bdc839b38d364e66af96b38dbb817e6332263322 Mon Sep 17 00:00:00 2001 From: HimanshuAwasthi95 Date: Sun, 11 Mar 2018 19:19:27 +0530 Subject: [PATCH 16/20] changes according guidance --- pandas/core/indexes/datetimes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 52b0dd42bbc9b..4e06f606160d7 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1939,7 +1939,7 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): """ Localize tz-naive DatetimeIndex to tz-aware DatetimeIndex. - This method takes a naive DatetimeIndex object and make this + 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 From fa75bf555e2edeb564c35ce9d199c0c2191c40a5 Mon Sep 17 00:00:00 2001 From: HimanshuAwasthi95 Date: Sun, 11 Mar 2018 22:28:15 +0530 Subject: [PATCH 17/20] update with return and example section --- pandas/core/indexes/datetimes.py | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 4e06f606160d7..d1ca055ad5fb4 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1978,34 +1978,26 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): Returns ------- DatetimeIndex + It returns naive time or aware time Examples -------- - In the example below, We put the date range from 01 March 2018 - to 08 March 2018 & localize this to US/Eastern Time zone & again - we perform reverse operation where we remove tize zone & make it - tz-naive + >>> tz_aware = pd.date_range('2018-03-01', '2018-03-03') - >>> dti = pd.date_range('2018-03-01', '2018-03-03') - - >>> dti + >>> tz_aware DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03'], dtype='datetime64[ns]', freq='D') - localize DatetimeIndex in US/Eastern time zone. - - >>> tz_aware = dti.tz_localize(tz='US/Eastern') + Localize DatetimeIndex in US/Eastern time zone. - >>> tz_aware + >>> tz_aware.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'], dtype='datetime64[ns, US/Eastern]', freq='D') - localize aware time zone into naive time zone. - - >>> tz_naive = tz_aware.tz_localize(None) + Localize aware time zone into naive time zone. - >>> tz_naive + >>> tz_aware.tz_localize(None) DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03'], dtype='datetime64[ns]', freq='D') From 85f6dbe5fd0bfe1dee2ca59dc6322de0935bdfad Mon Sep 17 00:00:00 2001 From: HimanshuAwasthi95 Date: Sun, 11 Mar 2018 22:45:48 +0530 Subject: [PATCH 18/20] Example Section --- pandas/core/indexes/datetimes.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index d1ca055ad5fb4..0e4aeff523efa 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1982,15 +1982,17 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): Examples -------- - >>> tz_aware = pd.date_range('2018-03-01', '2018-03-03') + >>> tz_naive = pd.date_range('2018-03-01', '2018-03-03') - >>> tz_aware + >>> tz_naive DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03'], dtype='datetime64[ns]', freq='D') Localize DatetimeIndex in US/Eastern time zone. - >>> tz_aware.tz_localize(tz='US/Eastern') + >>> tz_aware = tz_naive.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') From 6205b611e985379d47f2ac6d495216baebe5665b Mon Sep 17 00:00:00 2001 From: HimanshuAwasthi95 Date: Sun, 11 Mar 2018 23:31:56 +0530 Subject: [PATCH 19/20] Update changes --- pandas/core/indexes/datetimes.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 0e4aeff523efa..be0415ddf8c90 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1978,12 +1978,11 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): Returns ------- DatetimeIndex - It returns naive time or aware time + Index converted to the specified time zone. Examples -------- >>> tz_naive = pd.date_range('2018-03-01', '2018-03-03') - >>> tz_naive DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03'], dtype='datetime64[ns]', freq='D') @@ -1991,13 +1990,12 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): Localize DatetimeIndex in US/Eastern time zone. >>> tz_aware = tz_naive.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 time zone aware into naive time zone. >>> tz_aware.tz_localize(None) DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03'], @@ -2008,7 +2006,6 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): ------ TypeError If the DatetimeIndex is tz-aware and tz is not None. - """ if self.tz is not None: if tz is None: From 95fcee2ce8e87b1785de3b477b5f7ddf4b98cb7e Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Wed, 14 Mar 2018 09:54:54 +0100 Subject: [PATCH 20/20] Update datetimes.py --- pandas/core/indexes/datetimes.py | 60 ++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index be0415ddf8c90..344ec9f3a89de 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1939,20 +1939,19 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): """ Localize tz-naive DatetimeIndex to tz-aware DatetimeIndex. - 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 + This method takes a time zone (tz) naive DatetimeIndex object and + makes this time zone aware. It does not move the time to another + time zone. + Time zone localization helps to switch from time zone aware to time zone unaware objects. 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. + Time zone to convert timestamps to. Passing ``None`` will + remove the time zone information preserving local time. ambiguous : str {'infer', 'NaT', 'raise'} or bool array, \ - default 'raise' +default 'raise' - 'infer' will attempt to infer fall dst-transition hours based on order - bool-ndarray where True signifies a DST time, False signifies a @@ -1963,10 +1962,10 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): times errors : {'raise', 'coerce'}, default 'raise' - 'raise' will raise a NonExistentTimeError if a timestamp is not - valid in the specified timezone (e.g. due to a transition from + valid in the specified time zone (e.g. due to a transition from or to DST time) - 'coerce' will return NaT if the timestamp can not be converted - into the specified timezone + to the specified time zone .. versionadded:: 0.19.0 @@ -1974,38 +1973,45 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'): .. deprecated:: 0.15.0 Attempt to infer fall dst-transition hours based on order - Returns ------- DatetimeIndex Index converted to the specified time zone. + Raises + ------ + TypeError + If the DatetimeIndex is tz-aware and tz is not None. + + See Also + -------- + DatetimeIndex.tz_convert : Convert tz-aware DatetimeIndex from + one time zone to another. + Examples -------- - >>> tz_naive = pd.date_range('2018-03-01', '2018-03-03') + >>> tz_naive = pd.date_range('2018-03-01 09:00', periods=3) >>> tz_naive - DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03'], - dtype='datetime64[ns]', freq='D') + DatetimeIndex(['2018-03-01 09:00:00', '2018-03-02 09:00:00', + '2018-03-03 09:00:00'], + dtype='datetime64[ns]', freq='D') - Localize DatetimeIndex in US/Eastern time zone. + Localize DatetimeIndex in US/Eastern time zone: >>> tz_aware = tz_naive.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') + DatetimeIndex(['2018-03-01 09:00:00-05:00', + '2018-03-02 09:00:00-05:00', + '2018-03-03 09:00:00-05:00'], + dtype='datetime64[ns, US/Eastern]', freq='D') - Localize time zone aware into naive time zone. + With the ``tz=None``, we can remove the time zone information + while keeping the local time (not converted to UTC): >>> tz_aware.tz_localize(None) - DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03'], - dtype='datetime64[ns]', freq='D') - - - Raises - ------ - TypeError - If the DatetimeIndex is tz-aware and tz is not None. + DatetimeIndex(['2018-03-01 09:00:00', '2018-03-02 09:00:00', + '2018-03-03 09:00:00'], + dtype='datetime64[ns]', freq='D') """ if self.tz is not None: if tz is None: