From 7c8ae63d9af18fd203b8b9b78c6687f2dd135aee Mon Sep 17 00:00:00 2001 From: Anthony Delannoy Date: Sun, 2 Apr 2017 10:56:31 +0200 Subject: [PATCH] COMPAT: NaT support tz_localize / tz_convert (#15830) --- doc/source/whatsnew/v0.20.0.txt | 2 ++ pandas/_libs/tslib.pyx | 3 ++- pandas/tests/scalar/test_nat.py | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.20.0.txt b/doc/source/whatsnew/v0.20.0.txt index 230f39db67197..781a912555e14 100644 --- a/doc/source/whatsnew/v0.20.0.txt +++ b/doc/source/whatsnew/v0.20.0.txt @@ -837,6 +837,8 @@ Other API Changes ignored (no longer needed to specify the new behaviour) and is deprecated. - ``NaT`` will now correctly report ``False`` for datetimelike boolean operations such as ``is_month_start`` (:issue:`15781`) - ``NaT`` will now correctly return ``np.nan`` for ``Timedelta`` and ``Period`` accessors such as ``days`` and ``quarter`` (:issue:`15782`) +- ``NaT`` will now returns ``NaT`` for ``tz_localize`` and ``tz_convert`` + methods (:issue:`15830`) .. _whatsnew_0200.deprecations: diff --git a/pandas/_libs/tslib.pyx b/pandas/_libs/tslib.pyx index d441f1ec4759b..5aa8e15d0d087 100644 --- a/pandas/_libs/tslib.pyx +++ b/pandas/_libs/tslib.pyx @@ -3835,7 +3835,8 @@ for field in fields: # to the NaTType class; these can return NaT, np.nan # or raise respectively _nat_methods = ['date', 'now', 'replace', 'to_pydatetime', - 'today', 'round', 'floor', 'ceil'] + 'today', 'round', 'floor', 'ceil', 'tz_convert', + 'tz_localize'] _nan_methods = ['weekday', 'isoweekday', 'total_seconds'] _implemented_methods = ['to_datetime', 'to_datetime64', 'isoformat'] _implemented_methods.extend(_nat_methods) diff --git a/pandas/tests/scalar/test_nat.py b/pandas/tests/scalar/test_nat.py index ce2ed237f5559..0695fe2243947 100644 --- a/pandas/tests/scalar/test_nat.py +++ b/pandas/tests/scalar/test_nat.py @@ -129,7 +129,8 @@ def test_NaT_methods(): 'timetuple', 'timetz', 'toordinal', 'tzname', 'utcfromtimestamp', 'utcnow', 'utcoffset', 'utctimetuple'] - nat_methods = ['date', 'now', 'replace', 'to_datetime', 'today'] + nat_methods = ['date', 'now', 'replace', 'to_datetime', 'today', + 'tz_convert', 'tz_localize'] nan_methods = ['weekday', 'isoweekday'] for method in raise_methods: