Skip to content

Commit 2dbcd91

Browse files
committed
COMPAT: NaT support tz_localize / tz_convert (#15830)
1 parent d1e1ba0 commit 2dbcd91

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

pandas/_libs/tslib.pyx

+8-1
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,12 @@ class NaTType(_NaT):
845845
# GH 10939
846846
return np.nan
847847

848+
def tz_localize(self):
849+
return NPY_NAT
850+
851+
def tz_convert(self):
852+
return NPY_NAT
853+
848854
@property
849855
def is_leap_year(self):
850856
return False
@@ -3835,7 +3841,8 @@ for field in fields:
38353841
# to the NaTType class; these can return NaT, np.nan
38363842
# or raise respectively
38373843
_nat_methods = ['date', 'now', 'replace', 'to_pydatetime',
3838-
'today', 'round', 'floor', 'ceil']
3844+
'today', 'round', 'floor', 'ceil', 'tz_convert',
3845+
'tz_localize']
38393846
_nan_methods = ['weekday', 'isoweekday', 'total_seconds']
38403847
_implemented_methods = ['to_datetime', 'to_datetime64', 'isoformat']
38413848
_implemented_methods.extend(_nat_methods)

pandas/tests/scalar/test_nat.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ def test_NaT_methods():
129129
'timetuple', 'timetz', 'toordinal', 'tzname',
130130
'utcfromtimestamp', 'utcnow', 'utcoffset',
131131
'utctimetuple']
132-
nat_methods = ['date', 'now', 'replace', 'to_datetime', 'today']
132+
nat_methods = ['date', 'now', 'replace', 'to_datetime', 'today',
133+
'tz_convert', 'tz_localize']
133134
nan_methods = ['weekday', 'isoweekday']
134135

135136
for method in raise_methods:

0 commit comments

Comments
 (0)